View Full Version : Remove all symbols & quotes from string

03-10-2008, 09:59 AM
I need to get the user input as a keyword for displaying ads.
In order to get strings which user inputs with quotes or symbols like %$#@, I need to strip the string off of any symbols but NOT spaces.

eg. If the user inputs:
Hello "World"!
It should return:
Hello World

I can only use the string with no symbols & quotes to include as keywords for the site.


03-10-2008, 10:16 AM
Best way is to use preg_replace to clean out everything but what you actually want to allow like so:

$input = preg_replace( "#[^a-zA-Z0-9 ]#", "", $input);This allows for only letters, numbers and spaces. Hope this helps :)

03-10-2008, 10:24 AM
mbhramar, Read the rules first http://www.codingforums.com/postguide.htm. Don't cross post!

03-10-2008, 05:09 PM
oh I am sorry. Actually Earlier on, I needed this functionality in PHP. But then I realized that I actually need it in Javascript. So I ended up posting it again in Javascript.

03-10-2008, 05:09 PM
digitalfiz, Thanks alot bro for the solution.