Working with ampersands in $ _GET functions

If I have a URL, for example, asdf.com/index.php?a=0&b=2, then using $ _GET for awill be 0, and for bwill be 2. However, the term I put in one function $ _GET has an ampersand in it e.g. a = Steak & Cheese. Is there a way to make ampersands work without the $ _GET variable, assuming that its work ends when the ampersand appears (so it doesn't pull the whole term)?

+3
source share
3 answers

urlencode()therefore &turns into %26.

If you need to make a query string from some parameters, you can use http_build_query(), and it will encode the URLs for you.

$_GET PHP, a=Steak%26Cheese $_GET = array('a' => 'Steak&Cheese').

+5

Here is the previous post describing this in jQuery AJAX queries, but you have to encode uri to summarize. This converts the ampersand value to ascii value. Ampersand in GET, PHP

-1
source

All Articles