title: How do I remove blank lines from text in PHP?
body: <p>I need to remove blank lines (with whitespace or absolutely blank) in PHP. I use this regular expression, but it does not work:</p>
  
  <pre><code>$str = ereg_replace('^[ \t]*$\r?\n', '', $str);
  $str = preg_replace('^[ \t]*$\r?\n', '', $str);
  </code></pre>
  
  <p>I want a result of:</p>
  
  <pre><code>blahblah
  
  blahblah
  
     adsa 
  
  
  sad asdasd
  </code></pre>
  
  <p>will:</p>
  
  <pre><code>blahblah
  blahblah
     adsa 
  sad asdasd
  </code></pre>