Page 1 of 1

Seaching for a pattern from the end of a string

Posted: Thu May 31, 2007 2:27 pm
by plezops
I have the code

Code: Select all

$fileName 	= basename($_FILES['uploadedFile']['name']);
$fileExt	= eregi_replace('^.+\\.([^.]+)$', '\\1' , $fileName);
This works fine, what it does is looks for a period and then captures everything after that period, giving the file's extension. This will not give the extension though if there is another period in the file name. Is there a way to start from the end and work backwards then once a period is found it will capture everything at the end of the string like it currently does?

Another question is how I can separate the pieces of info into two different strings example: test.jpg is passed in as $fileName then I do the pattern search and break it up into 2 different strings one called $fileExt which would contain 'jpg' (no period, no ') and $fileName which would equal 'test' (again no period and no')

Any help in solving these 2 problems would be greatly appreciated!

Posted: Thu May 31, 2007 2:42 pm
by superdezign