As we know that PHP ereg() function is no more a part of PHP 5.3.x and I need an alternative for the following code with PHP preg_match():
ereg("(\.)([a-z0-9]{3,5})$", $file_name)
Any help will greatly be appreciated.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This should do it (if I understood the original regex properly)
It matches a string which ends with a
.followed by 3, 4 or 5 numbers or lower case letters, and those last letters/numbers will be in the first matching group now.If you’re looking to grab the extension of a file, perhaps this article might help: http://cowburn.info/2008/01/13/get-file-extension-comparison/
The TLDR version is this: