I have to create a nickname from the email address of the user. For example: mario-rossi79@gmail.com
in this case the nickname that I have to create should contain only alphanumeric characters: mariorossi79
How can I do that?
I have to create a nickname from the email address of the user. For example: mario-rossi79@gmail.com
in this case the nickname that I have to create should contain only alphanumeric characters: mariorossi79
How can I do that?
Try this:
$email = 'mario-rossi79@gmail.com';
$arr = explode("@", $email);
$result = preg_replace("/[^a-zA-Z0-9]+/", "", $arr[0]);
echo $result;
you can do it in 2 passes. first remove the @domain
second remove the none alpha numeric.
$email = "mario-rossi79@gmail.com";
$user = preg_replace("/@.*$/", "", $email);
$nickname = preg_replace("/[^A-Za-z0-9]/", "", $user);