Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remove all symbols & quotes from string

    Hi,
    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.

    Thanks

  • #2
    New Coder
    Join Date
    Mar 2008
    Location
    Lakeland, FL
    Posts
    39
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Best way is to use preg_replace to clean out everything but what you actually want to allow like so:

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

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    mbhramar, Read the rules first http://www.codingforums.com/postguide.htm. Don't cross post!
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    digitalfiz, Thanks alot bro for the solution.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •