php - Reading & character that is being passed through GET
I am reading content ofGET
query string, and every time I encounter&
for ecampleBlackstone Woodfire & Grill
,GET
is readingBlackstone Woodfire
.
How can I avoid this, if possible?
I know I could encode the special characters from the reference page, then decode them when are directed to this page.
I'm just curious.
Answer
Solution:
The problem is that the parameters you send using get, are separated using a &. So if you have an url like
You will have an $_GET array like
Now if you send and url like:
You will have an $_GET array like
Simply becuase that is the way sending GET params works. On the recieving side, there is not much you can do, the problem lies at the other end. The GET parameters that are beeing send must indeed be encoded, within PHP that is done using
Javascript uses encodeURIComponent() to solve this issue. PHP calles urldecode() automaticly on every get parameter when it is creating your $_GET global.
Answer
Solution:
You could use urlencode to encode the get string. And later if u want to fetch it from $_GET u urldecode.
You could replace all ampersands to %26