hi
I'm trying to get my head round regular expressions - i've got ones that will remove every non- a-z or 1-9 character but what i'm trying to do is make one for taking the extnsions off file names, so that
"this is my great filename.doc"
would be just
"this is my great filename"
it would need to be something that would match for a "." and then remove everything after it (in case the extension isn't a standard 3-letter one)
can anyone help please ? I'm a real noob at this ...........
thanks
another (simple) reg expression problem
Moderator: General Moderators
-
JustCantThinkOfAName
- Forum Newbie
- Posts: 2
- Joined: Wed Nov 26, 2003 8:38 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can get away without using regular expressions to do this:
For more info:
[php_man]pathinfo[/php_man]()
[php_man]basename[/php_man]()
Mac
Code: Select all
<?php
$file_name = 'this is my great filename.doc';
$file_info = pathinfo($file_name);
$file_no_extension = basename($file_info['basename'], '.'.$file_info['extension']);
echo 'file without extension: '.$file_no_extension;
?>[php_man]pathinfo[/php_man]()
[php_man]basename[/php_man]()
Mac
-
JustCantThinkOfAName
- Forum Newbie
- Posts: 2
- Joined: Wed Nov 26, 2003 8:38 am