homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Regex help please!

 11:08 am on Feb 28, 2011 (gmt 0)

Hello all,


I would like to know what the regex would be to capture the filename irrespective of what it is, but retrieve the file type so that I have a file name to work with. Then I can feed that into another function so that I can run a cron job and periodically 'check' this file.

If anyone has a better suggestion, please let me know.

Hope that makes sense.




 8:36 pm on Feb 28, 2011 (gmt 0)

The filename will always be after the final slash.

The extension will always be after the final period.

There will be no need for any
(.*) patterns at all; stuff like (([^/]+/)*) will strip the folder structure.

When you have found the filename and extension,
(([^.]+\.)+)([^./]+) will split the filename and extension.

 11:48 pm on Feb 28, 2011 (gmt 0)

Just to be sure we are on the same page, I am assuming you want to match the full filename and also the file extension from an image tag that points to a specific directory on a specific domain. Also note, this solution will only match the first image tag found in the supplied string.


$filename = $matches[1]; # Contents of the first backreference
$filetype = $matches[2]; # Contents of the second backreference

Note the parentheses:


These identify “backreferences” which are returned by the matches array starting at index 1.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved