You are here: Re: preg_match explanation « PHP Programming Language « IT news, forums, messages
Re: preg_match explanation

Posted by peter on 10/16/06 04:05

> Found this piece of code using preg_match to check file types during
> upload
> of files.
> $allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
> preg_match("/\." . $allowed_file_types . "$/i",
> $_FILES['uploadedfile']["name"])
>
> I understand the basic preg_match but am confused as to how the string
> pattern part is working i.e.
> "/\." . $allowed_file_types . "$/i"

the regular expression equates to the following:-

"/\.(jpg|jpeg|gif|bmp|png)$/i"

basically it is saying that the string MUST contain a . (which has been
escaped by the slash) plus jpg OR jpeg OR gif OR bmp OR png. AS you see the
| means OR when enclosed in brackets like it currently is. The $ states that
the match must be at the end of the string (or in this case the file name)
and the /i staes that the match should be case insensitive.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация