SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot suro's Avatar
    Join Date
    Jan 2005
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting numbers from a string

    Say I have a text like this

    sometext:158664;5486

    How can I only get the numbers to seperate variables if the number count is changeable?

    Thanks.

  2. #2
    SitePoint Zealot musher's Avatar
    Join Date
    Nov 2005
    Location
    Hull, England
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    PHP Code:
    $text preg_replace('/\D/','',$text); 
    Edit: Sorry, might have misread that. You want the numbers in seperate variables try..

    PHP Code:
    preg_match_all('/\d/',$text,$matches); 
    $matches[0] will the contain the variables

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use explode function

    $a_values = explode( ",", $text );


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
  •