SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Getting the domain and userid part from an email address

We can separate domain part and userid part of an email address in many ways. One of the easiest ways is to use split command 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 split command will give us an array with two elements. The first part is the userid and second part is domain part. Here is the code to get domain and userid part from a email address.





$em="mynam@domain.com";
$ar=split("@",$em);
echo $ar[0];
echo "<br>";
echo $ar[1];

If we have more than one email address in a string then we have to break the string first to get all the email address first. For example if we have one CSV file storing all the email address then first we have to break the file to get individual email address and then again use the split command to get the domain and userid part from the address. Here is the code.

$em="mynam@domain.com,second@second.com,
third@third.com,fourth@fourth.com";

$ar=split(",",$em);

while (list ($key, $val) = each ($ar)) {
$ar2=split("@",$val);
echo $ar2[0];
echo "<br>";
echo $ar2[1];
echo "<br><br>";
}


Read how breaking of email address is done using JavaScript



Shantha26-05-2010
It really helped me to solve my problem.
Anjana Silva25-11-2010
wow! this code works perfectly! thanks!
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
String Functions
PHP Sections