How to extract username from an e-mail address string

Save to StumbleUpon Stumble Upon it!   Save to Del.icio.us Save to Del.icio.us

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  RSS BitRepository RSS Feed.
   Save to StumbleUpon   

Similar entries

Comment on this post!

Subscribe to BitRepository RSS Feed
[Advertise with us]