GET search query won't work with & in the parameter


I've got a problem where if someone searches something like O&O, the query string is formed like this ?search=O&O but the ampersand tells GET that it's a new variable... How do I transfer an ampersand via GET?

Who is Participating?
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.

Form the query string by changing all instances of & to &. This could be done, for example, by using htmlspecialchars().

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
Perhaps on your $_GET['query'] you could use a str_replace()

$var = str_replace("&", "&amp", $_GET['query']);

or maybe putting it in an escape sequence, but I'm not sure how PHP would handle this:
$var = str_replace("&", "\&", $_GET['query']);
i-CONICAAuthor Commented:
Spot on. Thanks.
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.