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>"; ?> Quote Link to comment 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); ?> Quote Link to comment 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>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.