In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the php unicode how to convert Chinese characters, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
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];$c2 = $name[$i + 1];if (ord($c) >0) {/ / two-byte text $str. ='\ u'.base_convert (ord ($c), 10,16). Base_convert (ord ($c2), 10,16);} else {$str. = $c2;}} return $str } / / Decoding the UNICODE encoded content function unicode_decode ($name) {/ / Transcoding, converting the Unicode encoding to browsable utf-8 encoding $pattern ='/ ([\ w] {4})) / if (! empty ($matches)) {$name ='; for ($j = 0; $j < count ($matches [0])) $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;}
Above are two functions of php, one converts Chinese characters into unicode and the other converts unicode into Chinese characters.
JSON.stringify (data) at work; this method converts Chinese characters into unicode, but it fails to parse unicode into Chinese characters in php, so the study found that the original unicode format has changed, the correct unicode format is:\ u5730\ u65b9, Chinese characters mean 'place'. But during php reverse parsing, the unicode becomes u5730u65b9, without the slash. So it can be parsed by changing the format in such a case, like this: $name=unicode_decode (str_replace ('Upright Personality\ UPU65b9')); so it can be parsed correctly.
Thank you for reading this article carefully. I hope the article "how to convert unicode into Chinese characters in php" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 254
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.