[nycphp-talk] Sneaking in unwanted characters
Jeff
jsiegel1 at optonline.net
Wed Sep 10 16:44:15 EDT 2003
So...substr is the way to go...or at least try.
Jeff Siegel
-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of David Sklar
Sent: Wednesday, September 10, 2003 2:54 PM
To: NYPHP Talk
Subject: RE: [nycphp-talk] Sneaking in unwanted characters
> without asking why someone's email can't start with "www"... shouldn't
> the www in the second check be in parenthesis?
>
> preg_match('/^(www\.)/', trim($_POST['email'])) )
>
> maybe I'm wrong,, regular expressions get so confusing...
/^www\./ and /^(www\.)/ match identically. The only difference is that
the
one with the parentheses captures the enclosed text for later use, if
you
want it.
> alternately, and probably slower, you could just check for a match in
> the first 4 chars
>
> if (substr(trim($_POST['email']), 0, 4) == "www.")
>
> very brute, but very clear :)
Actually, this is faster. And better style, IMHO. If you are using a
regex
with no metacharacters (like ^www\.), you should use the string
functions
instead.
David
_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk
More information about the talk
mailing list