These 2 codes fragments have not been tested yet. Posted here for my convenience and yours if you find it useful.The following code is not mine, the author is PsychoCoderPlease go here to see his post http://www.dreamincode.net/code/snippet1822.htm Instructions: The urldecode
function in PHP does a pretty good job decoding URL's. One shortcoming
is with URL's that contain Unicode characters such as %0. This can
cause trouble, especially when working with fixed length string.
Just pass the function your URL
Snippet
//Function to decode URL's that contain Unicode characters
function unicode_urldecode($url)
{
//split the URL into an array
$url_array = split ("%",$url); //Make sure we have an array
{
//Loop while the key/value pair of the array
//match our list items
while (list ($k,$v) = each ($url_array)) {
//use base_convert to convert each character
}
}
//return the decoded URL
return ("$ret");
}
Using Regex
The other that I have found in PHP manual contribute by anonymous author Search for function chr $url = preg_replace('~%([0-9a-f])([0-9a-f])~ei', 'chr(hexdec("\\1\\2"))',
$url);
'M%C3%BCnchen' (which is what a Browser makes of an URL containing
verbatim utf-8) gives a nice 2-byte-unicode-char: 'München' |