I want to just get the left half of an email address ( the username
part of [email protected]
), so stripping the @ and any characters after it.
If you have PHP5.3 you could use strstr
$email = '[email protected]';
$username = strstr($email, '@', true); //"username"
If not, just use the trusty substr
$username = substr($email, 0, strpos($email, '@'));
$parts=explode('@','[email protected]');
echo $parts[0];// username
echo $parts[1];// email.com
you can split the string using explode()
$email = '[email protected]';
/*split the string bases on the @ position*/
$parts = explode('@', $email);
$namePart = $parts[0];
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