How to loop through files in a directory and output the contents of each file in a <div>
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6155533/loop-code-for-each-file-in-a-directory">Loop code for each file in a directory</a>  </p>
</blockquote>



<p>I assumed that I can reach this with following code but i think i make someting wrong with this code  <code>include($file[$])</code></p>

<pre><code>&lt;?php
$dir= opendir(".") or die ('Cannot open directory');
$div="&lt;div class=\"left1\"&gt;\n";
echo "&lt;div class=\"wrapper\"&gt;\n";
for( $i=0; $i&lt;6; $i++){
    while(($file = readdir($dir)) != false){
    if(preg_match("/php$/", $file)){
    echo $div;
    include($file[$i]); // HERE ITS NOT WORKING AS I WANT
    echo "&lt;/div&gt;\n";
    }
    }
}
echo "&lt;/div&gt;\n";

?&gt;
</code></pre>
