On Wednesday 21 February 2001 18:42, Kenneth R Zink II wrote:
> > I was just reading at DevShed on how to use Regular Expressions, but
> now I'm even more confused.
>
> Can someone please explain how I would use a REGEX to determine in and
> uploaded file is a .gif or .jpg file?
if (preg_match ('/\.(gif|jpg)$/i', $filename, $matches))
{
echo "Congratulations, it's a " . $matches [1] . "!<br>";
}
else
{
echo "Wrong file type!<br>";
}
Explanation:
/.../ are the "regular expression quotes", i.e. the real expression is
between these slashes
The "i" after them means "do a case insensitive match" (a "pattern
modifier")
\.(gif|jpg) means "match if the string contains a dot followed by either
"gif" or "jpg""
The dot has to be escaped (prepended with a backslash) because a dot in a
regexp has a special meaning: "match any char". The escaping makes it
behave as a literal dot
The "$" means "here has to be the end of the string" (an "anchor")
=> the entire pattern means
"match if the string ends with a dot followed by either 'gif' or 'jpg',
and ignore case for this"
--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)
I saw God --------- and she was black.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]