How to Extract domain name from email

This tutorial extract domain name from email account. you can use many way to achieve this below is simple step to get extract domain name.

Method 1

$email='domainextract@gmail.com';

$domain = substr(strrchr($email, "@"), 1);

strrchr return the matching character string to last character and substr extract substring from string. above example strrchr execute first and than substr. So, output is gmail.com

Method 2

$domain = array_pop(explode('@', $email));

explode function is used to convert string to array. array_pop is delete the last element from array.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply