PHP $_SERVER['REQUEST_URI'] returns question marks ? for utf-8 characters after the slash

315 Views Asked by At

I have a route.php which gets called for every php request to return a friendly uri.

In route.php it parses $_SERVER['REQUEST_URI'] to get the parameters. I have a problem now when the request uri contains utf-8 characters after the slash, it will become question marks.

For example this request work well, http://localhost/route.php/testing

$_SERVER['REQUEST_URI'] return /route.php/testing

but this does not work, http://localhost/route.php/良い

$_SERVER['REQUEST_URI'] return /route.php/??

Is there a way to get the parameters correctly?

1

There are 1 best solutions below

4
On

Try to encode the characters, like so:

mb_convert_encode($_SERVER['REQUEST_URI'],'HTML-ENTITIES','UTF-8');