php string/regex question..

Discussion in 'PHP' started by SedNaX, Jun 2, 2007.

  1. #1
    I have a string:

    $demo = 'john<br>doe';

    i want to convert this into two strings:

    $1 = 'john';
    $2 = 'doe';

    So i need a line of code that searched the string for <br>, removes it (str_replace should be fine) and assign everything before it to $1 and everything after it to $2.

    How can this be done? I believe with regex but am not sure...

    thanks :)
     
    SedNaX, Jun 2, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You're better of using explode() in this case.

    
    list($name, $lastname) = explode('<br>', $demo);
    
    echo $name; // john
    echo $lastname; // doe
    
    PHP:
     
    nico_swd, Jun 2, 2007 IP
    SedNaX likes this.