Separate email and user only from a string

Asked

Viewed 239 times

2

Hello,

I have the following string:

$string = uniqid(mt_rand(1, 999999))." [email protected]|example123456"

The string above is totally random, the only thing that doesn’t change is [email protected]|example123456.

I want PHP to only return [email protected]|example123456.

I Googled to see if there was any snippet or example, but I found nothing.

  • $str = explode(" ", $string); $userEmail = $str[1];

  • What is the origin of this string? I believe that at some point you have them separately!

2 answers

4


$str = explode(" ", $string);

$userEmail = $str[1];  // [email protected]|example123456

$partes = explode("|", $userEmail);

$email = $partes[0]; //[email protected]

$user = $partes[1]; // example123456

-2

Use regular expressions, in what language do you need to do? It would probably be something like this:

/w@/w|/w

Browser other questions tagged

You are not signed in. Login or sign up in order to post.