title: PHP HTML generation - using string concatention
body: <p>A question about different methods of outputting html from PHP; what are the performance differences between these:</p>
  
  <p>Method 1 - variable concatenation</p>
  
  <pre><code>$html = '';
  $html .= '&lt;ul&gt;';
  for ($k = 1; $k &lt; = 1000; $k++){
      $html .= '&lt;li&gt; This is list item #'.$k.'&lt;/li&gt;';
  }
  $html .= '&lt;/ul&gt;';
  echo $html;
  </code></pre>
  
  <p>Method 2 - output buffering</p>
  
  <pre><code>ob_start();
  echo '&lt;ul&gt;';
  for ($k = 1; $k &lt; = 1000; $k++){
      echo '&lt;li&gt; This is list item #',$k,'&lt;/li&gt;';
  }
  echo '&lt;/ul&gt;';
  </code></pre>
  
  <p>I suspect you get some performance hit from continually modifying and enlarging a variable; is that correct?</p>
  
  <p>Cheers!</p>
  
  <p>Thanks GaryF, but I don't want an answer about architecture - this question is about performance. There seem to be some different opinions / testing about which one is faster, which is why there is not an accepted answer as yet.</p>