title: Pull Images from directory - PHP
body: <p>I am trying to pull images simply from my directory /img and load them dynamically into the website into the following fashion.</p>
  
  <pre><code>            &lt;img src="plates/photo1.jpg"&gt;
  </code></pre>
  
  <p>That's it. It seems so simple but all of the code I have found basically doesn't work.</p>
  
  <p>What I have that I am trying to make work is this:</p>
  
  <pre><code>   &lt;?php
     $a=array();
     if ($handle = opendir('plates')) {
  while (false !== ($file = readdir($handle))) {
     if(preg_match("/\.png$/", $file)) 
          $a[]=$file;
  else if(preg_match("/\.jpg$/", $file)) 
          $a[]=$file;
  else if(preg_match("/\.jpeg$/", $file)) 
          $a[]=$file;
  
  }
  closedir($handle);
     }
  
   foreach($a as $i){
  echo "&lt;img src='".$i."' /&gt;";
   }
   ?&gt;
  </code></pre>