DonJuma
DonJuma

Reputation: 2094

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';

Upvotes: 1

Views: 156

Answers (2)

Vikash
Vikash

Reputation: 989

list($one, $two) = split("@", $word);

Upvotes: 0

Dagg Nabbit
Dagg Nabbit

Reputation: 76766

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

Upvotes: 4

Related Questions