Show Filename without Filetype

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
marce23
Forum Newbie
Posts: 11
Joined: Tue Apr 06, 2004 9:35 am

Show Filename without Filetype

Post by marce23 »

Hi!
How can i read in only the filename (without the Filetyp) of a file?
thx
marce23
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You always only get the filename. The filetype is a different variable in PHP.

If you're refering to the filetype-extension under Windows (e.g. myfile.txt), it's always three letters long and seperated by a dot. Hence you can can either use [php_man]substr[/php_man] and variants or [php_man]explode[/php_man].
marce23
Forum Newbie
Posts: 11
Joined: Tue Apr 06, 2004 9:35 am

Post by marce23 »

Oh thanks!
The [php_man]substr[/php_man] function is great!
marce23
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

marce23 wrote:Oh thanks!
The [php_man]substr[/php_man] function is great!
marce23
Reading the manual: priceless Image
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's not always three letters long. pathinfo() is a safer solution.
Post Reply