473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to remove whitespace from PHP output and preserve indentation

384 256MB
I have the below code and I'm working how I would go about getting it to align at the left and remove all the white space while keeping the formatting/indenting in place?

Edit: Its all contained in a PHP variable and once all is generated its echoed to screen.
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.         <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4.         <head>
  5.         <title>Site</title>
  6.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7.         <meta name="robots" content="noindex,nofollow" />
  8.         <meta name="googlebot" content="noarchive" />
  9.  
Oct 8 '10 #1
5 4691
Markus
6,050 Expert 4TB
This is not a PHP question. Moving to HTML.
Oct 8 '10 #2
ziycon
384 256MB
This is a PHP question as the source is being output by PHP, its all contained in a PHP variable and once all is generated its echoed to screen.
Oct 8 '10 #3
Markus
6,050 Expert 4TB
What computer screen are you using? Because you see it on your screen, it's a problem with your screen.
Oct 8 '10 #4
ziycon
384 256MB
Computer screen? What does that have to do with it?

The source is being generated with whitespace at the being of every line except the first line. I just want to remove the whitespace at the beginning of each line and preserve the indent formatting through the rest of the source code.
Oct 8 '10 #5
kovik
1,044 Expert 1GB
You want to remove the whitespace, but keep whitespace... I assume you men you just want to get rid of the tab at the start of every line? If so:

Expand|Select|Wrap|Line Numbers
  1. echo str_replace("\n\t", "\n", $content);
Oct 10 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string?...
4
by: Purdy | last post by:
I have an asp.net application. i export to excel, in exporting to excel i use an xslt to define the columns and look. on one of the fields i need the word 'qty' but i need it to look like ' ...
0
by: threecrans | last post by:
If you create a new server control, and override the Render method with the following code: protected override void Render(HtmlTextWriter output) { // <TABLE id="mytable">...
44
by: Joe | last post by:
Is Python going to support s syntax the does not use it's infamous whitespace rules? I recall reading that Python might include such a feature. Or, maybe just a brace-to-indentation preprocessor...
0
by: Trent USTA | last post by:
I'm having a problem with line feeds in an xslcompiledtransform in .net 2.0. I'm trying to use xsl to transform xml to a text file that can be read on a Unix box. The problem is that when I insert...
10
by: Hermann.Richter | last post by:
Is there any way to remove automatically all blank chars from the html sent to the client?? Example: ---------------------------------------------------------------- <? echo "HTML tags...
0
by: guilho | last post by:
Hi all! I'm newbie on php. On the web site i'm developing, i have encoutered a problem that i can't resolve. I have a script that makes the file upload, and then, based on the upload, it displays...
4
by: howa | last post by:
Consider an example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style> a { background-color:red;} </style> </head>
5
by: fahadqureshi | last post by:
i am trying to get a user input and use that input as part of a directory path. i have tried many way of doing this but cant get rid of the space. accfile1 = raw_input("Enter file name:") print...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.