Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 »
Code: Select all
if (ereg("[^:space:a-zA-Z0-9\.]",$author2))
{
echo 'Only use spaces, periods, and alhpa numeric charecters.';
$error=1;
}
this works fine if the variable has alpha numeric and periods but as soon as I throw in a space it goes haywire, any ideas why?
-
Burrito
- Spockulator
- Posts: 4715
- Joined: Wed Feb 04, 2004 8:15 pm
- Location: Eden, Utah
Post
by Burrito »
Moved to Regex.
Wish I could help, but I don't know much about the posix engine... would be easy to do in PCRE

-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 »
hell,i'll take any example of how to do it with any function

-
$phpNut
- Forum Commoner
- Posts: 40
- Joined: Tue May 09, 2006 5:13 pm
Post
by $phpNut »
this might not work, but try '\s' rather than :space: ...
-
Oren
- DevNet Resident
- Posts: 1640
- Joined: Fri Apr 07, 2006 5:13 am
- Location: Israel
Post
by Oren »
You can use: \s as $phpNut said, but this will allow new lines and tabs and not just spaces. Is that ok?
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 »
yep.it is.thanks a ton

I'll test it in a minute.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 »
Code: Select all
if (ereg("[^\sa-zA-Z0-9\.]",$author2))
{
echo 'Only use spaces, periods, and alhpa numeric charecters.';
$error=1;
}
that doesn't work either... : sigh : it worked in php4..why not php5.1.4

-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
[:space:] is the macro in Posix, I believe, but why use it when PCRE is faster and will be supported in future versions of php where Posix won't?