How to extract domain name from an e-mail address string
Posted on September 5, 2008, Filled under PHP,
Bookmark it
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
?>
Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!
- September 5, 2008
- article by Gabriel C.
- Leave a reply!
Sponsors
Related Posts
-
How to extract username from an e-mail address stringat September 5, 2008 with 2 comments
-
PHP: How to validate e-mail addresses using regular expressionsat May 21, 2008 with 2 comments
-
PHP: Convert E-Mail Addresses from a String into Clickable Linksat October 6, 2008 with 1 comment
-
PHP: How to extract numbers from a string (text)at October 5, 2008 with 1 comment
