Forum Moderators: coopster

Message Too Old, No Replies

How to strip out a filename extension

         

madmatt69

11:26 am on Sep 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone,

I know that you can get the URL of a file by using the get_uri fuction however I would also like to strip out the filename extension.

So for example, if get_uri returned "www.widgets.com/redwidget.php" I would want to be left with "redwidget".

Is there a way to do this?

Thanks for any help!

dcrombie

1:03 pm on Sep 23, 2005 (gmt 0)



You can use strrchr [php.net]
(see examples on that page)

;)

dmmh

2:28 pm on Sep 23, 2005 (gmt 0)

10+ Year Member



$str = $PHP_SELF;
$str = explode(".", $str);
$doc = $str[0];

should do the trick

ergophobe

11:31 pm on Sep 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the filename is in the url and you know the path, pathinfo() might help

$path = pathinfo('/server/path/to/file.exf');
$extension = $path['extension'];