Forum Moderators: coopster

Message Too Old, No Replies

Regex for images in MYSQL

         

maccas

5:09 pm on Jul 28, 2005 (gmt 0)

10+ Year Member



Hi, I have a script that allows uploads and I have this as a regex ^([%\w-]+\.(?:jpe?g¦JPE?G¦gif¦GIF¦png¦PNG)¦)$ it works fine if the image is named 1234.jpg but I am finding most people are uploading images that are like 12 35.jpg and the gap is causing them to get a error, any ideas on a regex for people that have caps or special characters in the file name?

jd01

6:46 pm on Jul 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about:

$yourvariable=strtolower($yourvariable); // remove caps

$yourvariable=preg_replace("/\s/", "", $yourvarible); // remove spaces

regex ^([%\w-]+\.(?:jpe?g¦JPE?G¦gif¦GIF¦png¦PNG))$

This will convert to lowercase, and replace spaces.

You could also just use eregi, which dictates no case - matches upper and lower - and then add \s - 'any space character' - to your current expression.

Hope this helps.

Justin