If, for any reason, you need to extract the domain from an e-mail address (or from multiple e-mail address that are in a database) then you can use this function:
<?php
function getDomainFromEmail($email)
{
// Get the data after the @ sign
$domain = substr(strrchr($email, "@"), 1);
return $domain;
}
// Example
$email = 'the_username_here@yahoo.com';
$domain = getDomainFromEmail($email);
echo $domain; // yahoo.com
?>
- September 5, 2008
- article by Gabriel C.
- 1 comment
Related Posts
-
PHP: How to validate e-mail addresses using regular expressionsat May 21, 2008 with 2 comments
-
Extract URL(s) from Link(s) with PHPat September 4, 2008 with 2 comments
-
How to extract images from an URL in PHPat August 30, 2008 with 9 comments
-
How to extract content between two delimiters in PHPat August 29, 2008 with 18 comments
-
Checking the beginning of a string (prefix)at August 30, 2008 with 1 comment

Comment via Facebook
One Reply to "How to extract domain name from an e-mail address string"
November 24, 2011 at 9:27 PM
This function returns all domain name after @ sign. I need only domain name like “yahoo” or “gmail” or “tcs” or “ibm” etc. for emails like “xyz@yahoo.co.in”.