PHP + Preg_replace:删除电子邮件中“+”后面的部分

In order to promote a website, I allow subscribers to invite friends by email and I reward them.

But, some of them, used an email list like:

user@example.com, user+1@example.com, user+2@example.com

And all that emails refers to user@example.com so they are all valid.

What is the preg_replace pattern that remove the part after '+' sign so I can, after that, explode and use array_unique to remove duplicate emails ?

Thanks.

I finally get it. Juste remove the part between '+' and '@' using:

preg_replace('/\+(.)*@/', '@', $emails);

Hope it will help.

P.S.: I'm sorry Bart you thought I give you my job to do: If I didn't give any code, it's because none of them works.

Try it with

preg_replace('/(.+)\+.+(@.+)/', '$1$2', $mail);

if user+@example.com should also be replaced, you can take

preg_replace('/(.+)\+.*(@.+)/', '$1$2', $mail);

to use preg_replace in your case, you can do the following:

$email = 'user+1@example.com';
$email = preg_replace("#(.+)\+.*@(.*)#", '$1@$2', $email);

easy

$email = preg_replace('/\+[^@]*/i' , '' , $email);