everisk Posted August 5, 2009 Share Posted August 5, 2009 I'm trying decode Unicode string pass via URL just like this website. I have trying and testing different functions found on Google but to no success Only this website produce accurate results. Any ideas? http://www.crypo.com/eng_urld.php Quote Link to comment https://forums.phpfreaks.com/topic/168900-solved-decode-unicode-string/ Share on other sites More sharing options...
taquitosensei Posted August 5, 2009 Share Posted August 5, 2009 You'll have to give us more than that. The string you're trying to decode and the Code you're using to decode the unicode. The results you're expecting. That's like saying. My car doesn't work. What's wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/168900-solved-decode-unicode-string/#findComment-891297 Share on other sites More sharing options...
everisk Posted August 6, 2009 Author Share Posted August 6, 2009 The string can be anything based on what user input. As of now I'm testing with Thai characters but I think there is a function that decode Unicode character to their correct language (just like http://www.crypo.com/eng_urld.php <-- this is actually what I expect). The page uses UTF-8 as encoding. The result is the character corresponding to the Unicode. For Thai language the code table is http://www.unicode.org/charts/PDF/U0E00.pdf. My test string is %u0E19%u0E32 which should output นา Quote Link to comment https://forums.phpfreaks.com/topic/168900-solved-decode-unicode-string/#findComment-891943 Share on other sites More sharing options...
Daniel0 Posted August 6, 2009 Share Posted August 6, 2009 <?php header('Content-type: text/html; charset=utf-8'); function unicode2utf8($c) { $output=""; if($c < 0x80) { return chr($c); } else if($c < 0x800) { return chr( 0xc0 | ($c >> 6) ).chr( 0x80 | ($c & 0x3f) ); } else if($c < 0x10000) { return chr( 0xe0 | ($c >> 12) ).chr( 0x80 | (($c >> 6) & 0x3f) ).chr( 0x80 | ($c & 0x3f) ); } else if($c < 0x200000) { return chr(0xf0 | ($c >> 18)).chr(0x80 | (($c >> 12) & 0x3f)).chr(0x80 | (($c >> 6) & 0x3f)).chr(0x80 | ($c & 0x3f)); } return false; } $string = '%u0E19%u0E32'; $string = preg_replace('#%u([0-9a-f]+)#ie', 'unicode2utf8(0x$1)', $string); echo $string; The unicode2utf8() function came from: http://php.net/manual/en/function.unicode-encode.php#79829 Quote Link to comment https://forums.phpfreaks.com/topic/168900-solved-decode-unicode-string/#findComment-891947 Share on other sites More sharing options...
everisk Posted August 8, 2009 Author Share Posted August 8, 2009 wowww .. thanks a lot, Daniel0! It works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/168900-solved-decode-unicode-string/#findComment-893620 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.