Extract Query String Email That Has Plus (+) Sign

I have a shortcut where an email is embedded along with a code like this.


In most cases this works, except like the above case where there is a plus (+) sign in the email. I have written the following code that works, but I am curious if there is a better way. I am using PHP to process this.

$val = $_GET['e'];
if (strstr($val, "@")) $e = str_replace(" ", "+", $val);
else $e = $val; 

Open in new window

Can you either confirm this is a good way to go or suggest an alternative.

Paul KonstanskiProject SpecialistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David S.Commented:
Thanks for supporting address tags (aka "plus addressing").

Have you tried URI encoding it?

Open in new window

or, if that doesn't work, double encoding it?

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul KonstanskiProject SpecialistAuthor Commented:
These emails are coming to me this way from another application. So I do not have control over how they are encoded and sent to my application. It is an automated link to sign up for an email delivery.
David S.Commented:
In that case, I suggest specifying the optional limit argument to str_replace, so you limit it to the first space, because only one "+" is allowed.

$val = $_GET['e'];
if (strstr($val, "@")) $e = str_replace(" ", "+", $val, 1);
else $e = $val;

Open in new window

Otherwise, the only thing you could really do is use a regular expression to check the format of the address, but such things aren't perfect.

Can you try with below code if it will give output similar to sent by external system.

$val = $_GET['e'];

if (strstr($val, "@"))
      $e = urldecode($val);
      $e = $val;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.