UNICODE encoding and decoding of Chinese characters in PHP & lt ;? Php encodes the content in UNICODE format: u56feu7247 (original: Image) functionunicode_encode ($ name) {$ nameiconv (UTF-8, UCS-2, $ name ); $ lenstrlen ($ name); UNICODE encoding and decoding of Chinese characters in PHP
0) {// two bytes of text $ str. = '\ U '. base_convert (ord ($ c), 10, 16 ). base_convert (ord ($ c2), 10, 16);} else {$ str. = $ c2 ;}return $ str ;}// decodes the UNICODE-encoded content in the format of \ u56fe \ u7247 (original: image) function unicode_decode ($ name) {// Convert the Unicode code to a UTF-8 code that can be viewed $ pattern = '/([\ w] +) | (\ u ([\ w] {4})/I '; preg_match_all ($ pattern, $ name, $ matches); if (! Empty ($ matches) {$ name = ''; for ($ j = 0; $ j <count ($ matches [0]); $ j ++) {$ str = $ matches [0] [$ j]; if (strpos ($ str, '\ u') = 0) {$ code = base_convert (substr ($ str, 2, 2), 16, 10); $ code2 = base_convert (substr ($ str, 4), 16, 10 ); $ c = chr ($ code ). chr ($ code2); $ c = iconv ('ucs-2', 'utf-8', $ c); $ name. = $ c;} else {$ name. = $ str ;}}return $ name;} // test case: // code $ name = 'image'; echo ''. unicode_encode ($ name ). ''; // decodes echo ''. unicode_decode ('\ u56fe \ u7247 '). '';