title: Display white spaces that precede the content of the line of the file - PHP
body: <p>I'm currently using foreach loop to display the contents of a text file. However, I want to also display the whitespaces that precede the actual content of the line. How to do so?</p>
  
  <pre><code>$loop_var = 0;
      foreach($lines as $line) {  
          $loop_var++;
          if ($loop_var == 1) {
              echo'&lt;div id="h1"&gt;' . $line . '&lt;/div&gt;';
          }
          if ($loop_var == 2) {
              echo '&lt;div id="h2"&gt;' . $line . '&lt;/div&gt;&lt;br /&gt;';
          }
          if ($loop_var &gt; 2) {
              if ($loop_var == 3) { echo '&lt;pre&gt;&lt;div id="code"&gt;'; }
              echo ($line) . "&lt;br /&gt;";
          }
      }
      echo '&lt;/pre&gt;&lt;/div&gt;';
  </code></pre>
  
  <p>Now, if the textfile contains the following:</p>
  
  <pre><code>blah
  blah
      blah
    blah
  </code></pre>
  
  <p>It is getting displayed as:</p>
  
  <pre><code>blah
  
  blah
  
      blah
  
    blah
  </code></pre>