Regex to remove all special chars... EXCEPT spaces

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

Post Reply
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Regex to remove all special chars... EXCEPT spaces

Post by fluidbyte »

I'm using a regular expression to remove all special characters from a string, however, I want to be able to leave spaces in the string, any ideas?

Code: Select all

 
preg_replace("/[^a-zA-Z0-9s]/", "", $pagTitle);
 
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Re: Regex to remove all special chars... EXCEPT spaces

Post by fluidbyte »

nevermind, I figured it out:

Code: Select all

 
preg_replace("/[^a-zA-Z0-9\s]/", "", $pagTitle);
 
Does anyone have a good regular expression reference for newbs?
Post Reply