Search code examples
phpstringemailsplit

Split string on a delimiting character into two variables


Sample input:

$word = '[email protected]';

Can I make variables to contain everything up to the "@" and everything after?

Desired result:

$one = 'abcdefg';
$two = 'hijk.lmn';

Solution

  • use explode.

    $word = '[email protected]';
    $my_array = explode('@', $word);
    echo $my_array[0]; // prints "abcdefg"
    echo $my_array[1]; // prints "hijk.lmn"
    

    http://php.net/manual/en/function.explode.php