Current Code I'm using to get email suffix
$emailarray = explode('@',$email_address);
$emailSuffix = $emailarray[1];
There's gotta be a more efficient function. Maybe something using substr()
?
Shorter:
$emailSuffix = end(explode('@', $email_address));
But I don't think it gets any significantly more efficient than that. Regex is probably slower.
I did some testing and although this version was 3 times faster than using the
$a = explode('@', $email_address);
$foo = $a[1];
and
if (preg_match('~^.+@(.+)$~', $email_address, $reg))
$foo = $reg[1];
it doesn't comply with the strict standards:
Strict Standards: Only variables should be passed by reference
$foo = substr($email_address, strpos($email_address, '@'));
is about as fast as the end(explode(.)) method so I would suggest that one. Please see rayman86's answer and comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With