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

Posted by Michael Winter on 03/07/06 01:08

On 06/03/2006 22:56, Andrew Richardson wrote:

> $result = preg_match("[0-9][0-9]","12")
>
> gives me an error of: Unknown modifier '['
>
> and
>
> $result = preg_match("hello","hello")
>
> gives me an error of: Delimiter must not be alphanumeric or backslash
>
> Am I doing something wrong here?

You aren't including delimiters. The first character in a pattern will
be considered to be a pattern delimiter. A closing delimiter marks the
end of the pattern and the start of the flags.

In the first example above, the opening bracket is treated as the
delimiter and the next unescaped closing bracket will end the pattern.

In the second example, there are no delimiters at all.

There are various characters that can be used. Braces and brackets
(round, square, or angle), are considered in pairs. That is, the opening
bracket marks the start of the pattern, and the closing bracket ends it.
Any other non-alphanumeric or backslash character is used twice; the
same character starts and ends the pattern.

A common delimiter is the forward slash:

$result = preg_match('/[0-9][0-9]/', '12');

Hope that helps,
Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.

 

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

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