php - Using glob to filename parameters -
here's need, have files: "page-home1.php", "page-contact2.php". yes understand don't have beautiful names that's not i'm worrying right now, need glob echo files in order 1,2,3 etc..
i have:
<?php foreach (glob("page-*") $filename) { $result = str_replace("page-","", $filename); $result = str_replace(".php","", $result); echo "<li><a href='" . $filename ."'/>". $result . "</a></li><tr>"; } ?>
though spits them out in random order, need number order.... ideas?
$files = glob(dirname(__file__).'/page-*.php'); foreach ($files $file) { $result[preg_replace('#[^0-9]#','', $file)]['file'] = $file; $result[preg_replace('#[^0-9]#','', $file)]['name'] = str_replace(array("page-", ".php"), array('', ''), $file);; } sort($result); foreach($result $data) { echo $data['file'].' -> '.$data['name'].'<br>'; }
Comments
Post a Comment