$em="mynama@domain.com";
$ar=explode("@",$em);
echo $ar[0]; // myname
echo "<br>";
echo $ar[1];//domain.com
We can separate domain part and Userid part of an email address in many ways. One of the easiest ways is to use explode() to break the email address in two parts. As we know every email address will have one @ within it so we will break the string storing the email address using this @. The output of explode() command will give us an array with two elements. The first part is the userid and second part is domain part.
$em="mynam@domain.com,second@second.com,
third@third.com,fourth@fourth.com";
$ar=explode(",",$em);
while (list ($key, $val) = each ($ar)) {
$ar2=explode("@",$val);
echo $ar2[0];
echo "<br>";
echo $ar2[1];
echo "<br><br>";
}
Read how to use explode to get userid and domain part from an email address.Shantha | 26-05-2010 |
It really helped me to solve my problem. |
Anjana Silva | 25-11-2010 |
wow! this code works perfectly! thanks! |
Alastair | 15-03-2013 |
I suggest trying explode() or preg_split() instead because split() was deprecated with PHP 5.3 (2009-06-30). |