RE: preg_match problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 1/22/2007 04:56 PM, Beauford wrote:
I've probably read 100 pages on this, and no matter what I try it doesn't
work. Including all of what you suggested above - is my PHP possessed?

if(preg_match("/^[A-Za-z0-9!@#$%&()*;:_.'/\\ ]+$/", $string)) { gives me
this error.

Warning: preg_match() [function.preg-match]: Unknown modifier '\' in
/constants.php on line 107

So if If you wouldn't mind, could you show me exactly what I need right from
the beginning and explain why it works.

i.e.

if(preg_match(what goes here", $string)) {
Echo "You got it";


Beauford,

Because you're using forward slashes /.../ to delimit your pattern, regexp is using the / in your character class to terminate your pattern:

        /^[A-Za-z0-9!@#$%&()*;:_.'/

Then it's looking at the subsequent characters as pattern modifiers and gacking on the backslash. Even if you had a character there that it could accept as a pattern modifier, the character class would be incomplete (no closing bracket) so the pattern is doomed to fail.

You need to escape that forward slash in the character class:

        preg_match("/^[A-Za-z0-9!@#$%&()*;:_.'\/

Also, you've got only two backslashes in your char class. PHP is reducing this to a single backslash before the space character. I think you intend this to be two backslashes in the pattern so you need four backslashes in PHP:

        preg_match("/^[A-Za-z0-9!@#$%&()*;:_.'\/\\\\ ]+$/", $string)

Regards,

Paul
__________________________

Juniper Webcraft Ltd.
http://juniperwebcraft.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux