Preg_Math RegEx snippet help!

Discussion in 'PHP' started by JosS, Sep 24, 2007.

  1. #1
    I have a variable, for example

    $name which is

    4762840941_here-alone

    I need to extract the

    number section out, and the here-alone part like so:

    $nameid = "here-alone";
    $nameno = "4762840941";

    The $name variable can change to something longer like this:

    12312312312392_here-i-am

    Is this possible?
     
    JosS, Sep 24, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    list($nameid, $nameno) = explode('_', $name);
    
    echo $nameid;
    
    PHP:
    Assuming there will always be one underscore.
     
    nico_swd, Sep 24, 2007 IP
  3. JosS

    JosS Guest

    Messages:
    369
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Brilliant, works a charm! This will come in very handy for me now!
     
    JosS, Sep 24, 2007 IP