Simple PHP Help

Discussion in 'PHP' started by ofir12, Jun 26, 2011.

  1. #1
    Hey ,

    Lets say I have userid=123-456-765

    How can I put in variable only the " 123 " it can be also 12345 , I mean how can I take all numbers from start until the first "-" and put them in a variable.

    Thank you in advance for your help !
     
    ofir12, Jun 26, 2011 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Play with this:
    
    $userid = '123-456-765';
    $parts = explode('-', $userid);
    print_r($parts)
    
    Code (markup):
     
    rainborick, Jun 26, 2011 IP
  3. kinggomez

    kinggomez Active Member

    Messages:
    268
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Simplest way:

    $userid = '123-456-765';
    $num = explode('-', $userid);
    $newid = $num[0];
    echo $newid;
    Code (markup):
     
    kinggomez, Jun 28, 2011 IP