How to remove whitespace from PHP output and preserve indentation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    How to remove whitespace from PHP output and preserve indentation

    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.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
            <title>Site</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <meta name="robots" content="noindex,nofollow" />
            <meta name="googlebot" content="noarchive" />
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    This is not a PHP question. Moving to HTML.

    Comment

    • ziycon
      Contributor
      • Sep 2008
      • 384

      #3
      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.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        What computer screen are you using? Because you see it on your screen, it's a problem with your screen.

        Comment

        • ziycon
          Contributor
          • Sep 2008
          • 384

          #5
          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.

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            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:

            Code:
            echo str_replace("\n\t", "\n", $content);

            Comment

            Working...