I think I have the need to take a uri which has been decoded in PHP, and re-encode it.
Here is the situation:
- JavaScript passes encoded uri as query string parameter to php script.
- PHP script embeds uri as a hidden input value in an html document, responds with the document to a user agent.
- JavaScript reads embedded uri and sets location of current document based on value of hidden input.
On Step 2, I am finding that the Uri is fully decoded after reading it in via $_GET. So when I embed the uri in the hidden input, it becomes un-encoded. So I would like to run a PHP script which re-encodes the Uri properly ex:
http://my.example.com/dog walk?is=very great
==>
http://my.example.com/dog%20walk?is=very%20great
Is there a pre-built php function for this or should I just write my own?
PLEASE NOTE: urlencode and urldecode are not the answer to get the desired input/output I have in the example above.
Thanks,
Macy
I don’t know if will help you, but PHP have 3 useful functions:
or, if you want to mount a query, you can use http_build_query(); that accepts values from an array, like: