php - Filtering To Be Displayed Images By Spesific Characters in their file Name -


i using code load .png images located in img directory need select , render images starting abcdef character selected , displayed. foe example

╔═════════════════════╦═══════════════════╗ ║ abcdef_seaview.png  ║ selected  ║  ╠═════════════════════╬═══════════════════╣ ║ ghijkl_seaview.png  ║ ignored   ║ ╚═════════════════════╩═══════════════════╝ 

here code:

<?php     $dirname = "../img/";     $images = glob($dirname."*.png");      foreach($images $image) {         $filename = basename($image);         echo '<div class="img-panel">';         echo '<img src="'.$image.'" class="" alt=""/>';         echo '</div>';      } ?> 

check starts before creating ui.

<?php     $dirname = "../img/";     $images = glob($dirname."*.png");     foreach($images $image) {         $filename = basename($image);         if (startswith($filename, "abcdef") {             echo '<div class="img-panel">';             echo '<img src="'.$image.'" class="" alt=""/>';             echo '</div>';         }     }  function startswith($haystack, $needle) {     // search backwards starting haystack length characters end     return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; } ?> 

Comments