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

Posted by Kimmo Laine on 10/25/90 11:34

"awebguynow" <i_dvlp@hotmail.com> kirjoitti
viestissδ:1134440951.325986.300530@o13g2000cwo.googlegroups.com...
>I ran across this code, and it kind of made me nervous: (as an email
> validator)
>
> if ( !preg_match("/.*\@.*\..*/", $_POST['email']) | preg_match("/(\)/",
> $_POST['email']) )
>
> 1) from bitwise experience with "C", I was not at all comforable with
> !preg_match()
> The manual is not clear about using ! with a non-boolean value.
> When using !($var) is ($var) converted to a boolean value, before
> doing the NOT oper ?
>
> 2) I believe the 2nd use of preg_match was the one that caused a
> REGEX compilation error.
> Warning: preg_match() [function.preg-match]: Compilation failed:
> missing ) at offset 3 in ..
>
> can anyone help ?


The missing ) is here: /(\)/
since you are using the backslash, which is an escape character, it escapes
the ), but actually you should be using
/(\\)/
so that it instead another backslashs escapes the backslash you wanted to
use in the first place. It is a cumbersome thing but you'll get the hang of
it I'm sure.

And fear not, all values are cast to boolean when you do boolean operations
with them. Althouh I would recommend you to use || instead of | since you
really aren't doing bitwise comparison here. But that's up to you really.

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <antaatulla.sikanautaa@gmail.com.NOSPAM.invalid>

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация