By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,507 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

How to remove whitespace from PHP output and preserve indentation

100+
P: 384
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
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
This is not a PHP question. Moving to HTML.
Oct 8 '10 #2

100+
P: 384
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
Expert 5K+
P: 6,050
What computer screen are you using? Because you see it on your screen, it's a problem with your screen.
Oct 8 '10 #4

100+
P: 384
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
Expert 100+
P: 1,044
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

Post your reply

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