PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Fri Sep 10, 2004 2:59 pm
You are correct. It should be:
'/[^a-zA-Z]/' is all characters that are not a-z or A-Z
'/[^0-9\-]/' is all characters that are not 0-9 or dash
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 10, 2004 3:07 pm
arborint wrote: You are correct. It should be:
'/[^a-zA-Z]/' is all characters that are not a-z or A-Z
'/[^0-9\-]/' is all characters that are not 0-9 or dash
only matches 1 character.. any character in the string.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Fri Sep 10, 2004 4:54 pm
No, it will remove all occurances that are not in the set given. For example:
$str = preg_replace('/[^a-zA-Z]/', '', $str);
will remove all characters except letters. It's probably the most generic way to filter strings.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 10, 2004 4:56 pm
with replace yes, I was talking about matching.