LiamProductions Posted August 12, 2007 Share Posted August 12, 2007 Hey. I've made a script to get all the .php extension files in the directory and make a link to them. Now. I was wondering how do i make it so that i can make it so the filetype comes at the end like PHP or .php I have tried filetype($filename) but it says file :s Heres code: <?php error_reporting(E_ALL); foreach(glob("*.php") as $filename) { echo "<center>"; echo "<table border=\"0\ cellspacing=\"50\"><tr><td><a href=\"$filename\">$filename</a></td><td> " . filesize($filename) . "KB</td><td>" . filetype($filename) . "</td></tr></table>"; } echo "</center>"; ?> Link to comment https://forums.phpfreaks.com/topic/64508-quick-solve/ Share on other sites More sharing options...
MrBillybob Posted August 12, 2007 Share Posted August 12, 2007 http://www.php.net/manual/en/function.pathinfo.php or just do this <?php $extension = substr(strrchr($filename, "."), 1); ?> Link to comment https://forums.phpfreaks.com/topic/64508-quick-solve/#findComment-321544 Share on other sites More sharing options...
Guest Posted August 12, 2007 Share Posted August 12, 2007 Well you could try $ext = substr($filename, strrpos($filename, '.')+1); // if $filename == 'test.php' : $ext = "php" // if $filename == 'myscript.inc' : $test = "inc" If you want to include the period before the extension, remove the +1 at the end in the code above -- then just use $ext and place it where you need it. OR you could simply hardcode it into your code: <?php error_reporting(E_ALL); foreach(glob("*.php") as $filename) { echo "<center>"; echo "<table border=\"0\ cellspacing=\"50\"><tr><td><a href=\"$filename\">{$filename}.php</a></td><td> " . filesize($filename) . "KB</td><td>" . filetype($filename) . ".php</td></tr></table>"; } echo "</center>"; ?> Link to comment https://forums.phpfreaks.com/topic/64508-quick-solve/#findComment-321545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.