php method to convert Chinese characters into pinyin: 1. Create a PHP sample file; 2. Pass "
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How does php convert Chinese characters into pinyin?
PHP Converting Chinese characters to Pinyin is one of the tasks that programmers often need to perform. Even though this small function can play a big role, the following is the correct way to convert Chinese characters to Pinyin. Everyone You can learn from it.
The specific code is as follows:
0&&$num<160){ return chr($num); } elseif($num<-20319||$num>-10247){ return ""; }else{ for($i=count($d)-1;$i>=0;$i--){if($d[$i][1]<=$num)break;} return $d[$i][0]; } } function c($str){ $ret=""; for($i=0;$i160){ $q=ord(substr($str,++$i,1)); $p=$p*256+$q-65536; } $ret.=g($p); } return $ret; } $hz = $_POST[hz]; echo c($hz); ?> Copy after login
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert Chinese characters into pinyin in php. For more information, please follow other related articles on the PHP Chinese website!