How to extract username from an e-mail address string
If you need to extract the username from an e-mail address string then this snippet can help you. For instance, you can use this function inside a loop, while selecting emails from a database.
<?php
function getUsernameFromEmail($email)
{
$find = '@';
$pos = strpos($email, $find);
$username = substr($email, 0, $pos);
return $username;
}
$email = 'thecoder@domain.com';
$username = getUsernameFromEmail($email);
echo $username; // thecoder
?>
The archive is made using WinZip 12.0. If you're having problems unzipping it, consider using WinRar, WinAce or a similar software to extract the files from the archive.Be notified when we have new posts by subscribing to


Comment on this post!