Page 1 of 1

another (simple) reg expression problem

Posted: Wed Nov 26, 2003 8:38 am
by JustCantThinkOfAName
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

Posted: Wed Nov 26, 2003 9:02 am
by twigletmac
You can get away without using regular expressions to do this:

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;
?>
For more info:
[php_man]pathinfo[/php_man]()
[php_man]basename[/php_man]()

Mac

Posted: Wed Nov 26, 2003 9:13 am
by JustCantThinkOfAName
Hi - it's a big relief not to have to use a regular expression!
I'll look at those two functions in more detail
Thank you