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 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Explode to Extract Only Letters and Numbers

    How can I explode a variable so that it takes out any punctuation (or anything that isn't a letter/number) and then saves the new content to a new variable.

    Example:
    -.Xibe.35- would return as: Xibe35

    Please help!!

    Thanks,
    Xibe

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    You can use regular expressions.

    PHP Code:
    $string="-.Xibe.35-";
    $pattern='/[^a-z0-9]/i'//find everything that is not a letter(case insensitive) and not a number.
    $replacement="";
    print 
    preg_replace($pattern,$replacement,$string); 

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    66
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks a lot for helping me out there!


  •  

    Posting Permissions

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