How about
$email = 'test@example.com';
$domain = substr(strstr($email, '@'),1);
echo $domain;
Also try
$email = 'test@gmail.com';
$domain = explode('@',$email);
$domain = $domain[1];
echo $domain ;
Question
I have an issue of getting the domain address of an email, In the substring this is the code.
$to=$son_im_email;//udemesamuel256@gmail.com
$goto_small=strtolower($to);
//this is what i want to achieve is just to get the 'GMAIL.COM' from the email address.
Solution 2
How about
$email = 'test@example.com';
$domain = substr(strstr($email, '@'),1);
echo $domain;
Also try
$email = 'test@gmail.com';
$domain = explode('@',$email);
$domain = $domain[1];
echo $domain ;
OTHER TIPS
An alternative to using "explode" or a regular expression:
<?php
$address = 'someuser@my.smalldomain.info';
$details = parse_url('mailto://'.$address);
var_dump($details);
?>
The output:
array(3) {
'scheme' =>
string(6) "mailto"
'host' =>
string(19) "my.smalldomain.info"
'user' =>
string(8) "someuser"
}
So you can use the domain name as $details['host']
.
Documentation from http://uk1.php.net/preg_match
$matched = preg_match("@.+$", $goto_small, $matches);
$matched
will be an int telling you whether @anything
could be found, and $matches
will be an array whose first element will be the @
and everything after it, if the function suceeded.