php to make Unicode codec online conversion tool code sharing
The code is as follows: <?php function Unicode_encode ($name) { $name = iconv (' UTF-8 ', ' UCS-2 ', $name); $len = strlen ($name); $STR = '; for ($i = 0; $i < $len-1; $i = $i + 2) { $c = $name [$i]; &nbs P $c 2 = $name [$i + 1]; if (ord ($c) > 0) { //two bytes of text $STR. = ' u ' base_convert ord ($c). Str_pad (Base_convert (Ord ($c 2), a), 2, 0, str_pad_left); } else { & nbsp $STR. = $c 2; } } return $str; //decoding of Unicode encoded function Unicode_decode ($name) { //conversion code, converting Unicode encoding to browsable utf-8 encoding & nbsp $pattern = '/([w]+) | (U ([w]{4}))/I '; Preg_match_all ($pattern, $name, $mAtches); if (!empty ($matches)) { $name = '; -FO R ($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); $code 2 = Base_convert (substr ($STR, 4), 16, 10); $c = chr ($code) Chr ($code 2); $c = iconv (' UCS-2 ', ' UTF-8 ', $c); $name. = $c; else &NB Sp { &NBSp $name. = $str; { } return $name; }