Separate only the email and user from a string

2

Hello,

I have the following string:

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

The above string is totally random, the only thing that does not change is [email protected]|example123456 .

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

I looked in Google to see if I already had a snippet or example, but I did not find anything.

    
asked by anonymous 26.02.2017 / 12:08

2 answers

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

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

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

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

$user = $partes[1]; // example123456
    
26.02.2017 / 23:55
-2

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

/w@/w|/w
    
27.02.2017 / 03:01