Re: Eregi error

From: Date: Fri, 02 Mar 2007 00:48:53 +0000
Subject: Re: Eregi error
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-249698@lists.php.net to get a copy of this message
On Thu, March 1, 2007 6:14 pm, Myron Turner wrote: > Roberto Mansfield wrote: >> Myron Turner wrote: >> >>> M.Sokolewicz wrote: >>> >>>>>> $pattern = '^[a-z0-9\!\_ \.- ,/]*$'; >>>>>> if(!eregi($pattern, $input)){ >>>>>> >>> the problem is that the hyphen is interpreted as regex range >>> operator: >>> [a-z0-9\!\_ \.- ,/] >>> Rewrite this as >>> [a-z0-9\!\_ \. ,/-] >>> with the hyphen in the last position. >>> >>> >> >> Or just escape the hyphen: \- >> The position won't matter. >> >> > > Actually, I tried that, but it didn't work. It still saw the hyphen > as > an operator. The other thing about this is that the hyphen is > followed > by a space, so that it's asking for a range between the period and the > space, which you can't do, since the space character has a lower ascii > value than than the period. The space is more obvious in a monospaced > font. The reason that a single \ in front didn't work is that \ is ALSO special character for ' in PHP, and it just escapes the - so that you have NOT sent \- to EREG, but sent it the same thing you were sending it before you added \ You would need \\ inside of '' (or "") in PHP to get a single \ sent to EREG which would then be used by EREG to escape the - '...\\- ,/' PHP takes \\- to produce \- which EREG takes to produce [character -] instead of [range operator -] You should probably review the "strings" page at the beginning of the PHP manual. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#249698) next »