Php $ _SERVER ['REQUEST_URI'] encoding issue?

When I output $_SERVER['REQUEST_URI'];

on:

http://localhost/tools/?tool=cs&sub=1

      

I get:

/tools/?tool=cs⊂=1

      

Is there any other solution to get /tools/?tool=cs&sub=1

other than using &

instead &

?

+2


source to share


3 answers


This is because you echo it to the browser - &sub

interpreted as an HTML object (& sub;).

If you are echo htmlentities($_SERVER['REQUEST_URI']);

, you will get what you expect.



You must be using the correct encoding for the environment you are in - in HTML, which means using &

.

+4


source


try it



echo urldecode($_SERVER['REQUEST_URI']);

      

+1


source


How do you infer this value? If you dump it to the browser, are you sure it isn't trying to "decode" embedded ampersands?

Try the file with

<?php phpinfo();

      

and see how this value is displayed (bottom)

0


source







All Articles