SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove everything except numbers

    Hi, is there a simple command that will take a string and remove everything that is not a number?

    So $100,000 would simply become 100000

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Location
    Toronto
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regular expressions are your friend

    Removing everything but numbers:
    PHP Code:
    $string preg_replace("/[^0-9]+/"""$string); 
    [0-9]+ means match a number (of any length > 1)
    the ^ negates this regexp, meaning match anything BUT numbers


Bookmarks

Posting Permissions

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