On a request URL, I can get the query string ?dir=Documents%20partag%C3%A9s or ?dir=Documents%20partag%E9s. I think the first one is UTF-8 and the second is ASCII.
The real string is : Documents partagés
So, I have a PHP script (in UTF-8) and what I want to do, is to detect if the query string is ASCII or UTF-8, and if ASCII, convert it to UTF-8.
I tried with mb_ functions, but the query string is always detected as ASCII and urldecode version of query string as UTF-8.
How can I achieve this? Note that Wikipedia has a similar function -it encodes itself %E9 to %C3%A9.
E9is 233 in decimal. It is not a valid ASCII byte (0-127 only), but it iséin ISO-8859-1 (Latin1). When usingmb_convert_encoding, you can specify multiple encodings (e.g.: UTF-8 and ISO-8859-1).This should fix it:
With the following script:
I get: