PHP MySQL Tutorial
Learn PHP and MySQL

Remove a File Extention Using PHP

Page Details

Published by:
admin
on 12-20-2008
2 people found this article useful.

100% of people found this useful
Remove a File Extention Using PHP

To strip the file extension from a file name you can use the combination of strrpos() and substr() function like this :

$name = substr($fileName, 0, strrpos($fileName, '.'));

For example, if $fileName is my-pretty-flowers.jpg then strrpos($fileName, '.') will return the last location a dot character in $fileName which is 17. So substr($fileName, 0, strrpos($fileName, '.')) equals to substr($fileName, 0, 17) which returns 'my-pretty-flowers'

Recent Comments

By: saif Posted on 06-29-2009 2:35 AM

Dear,

I want to make link where page extension won't be shown in url bar.

Is it possible with tour this tutorial

I have tried, but not succeed,

Here is something what i have done:

<?php

$fileName = 'overall.php';

$name = substr($fileName, 0, strrpos($fileName, '.'));

echo $name;

?>

<a href="<?php echo $name; ?>">link</a>

I f any one have solution, plz reply.

By: Clare Posted on 11-24-2009 4:28 PM

This might work for you:

$filename = 'overall.php';

$name = substr($fileName, 0, -4);

echo = $name;

result: overall

Powered by Community Server (Non-Commercial Edition), by Telligent Systems