How to get a substring from string through PHP?
list($username, $domain) = explode('@', '[email protected]')
Use strstr function.
An example from the PHP reference -
<?php
$email = '[email protected]';
$domain = strstr($email, '@');
echo $domain; // prints @example.com
$user = strstr($email, '@', true); // As of PHP 5.3.0
echo $user; // prints name
?>
Try this:
$username = substr($username, 0, strpos($username, '@'));