PHP汉字转拼音函数
程序员文章站
2022-04-03 11:42:56
...
160) { $_Q = ord(substr($_String, ++$i, 1)); $_P = $_P*256 + $_Q - 65536; } $_Res .= _Pinyin($_P, $_Data); } return preg_replace("/[^a-z0-9]*/", '', $_Res); } function _Pinyin($_Num, $_Data){ if($_Num>0 && $_Num-10247){ return ''; }else{ foreach($_Data as $k=>$v){ if($v>6); $_String .= chr(0x80 | $_C & 0x3F); }elseif($_C >12); $_String .= chr(0x80 | $_C>>6 & 0x3F); $_String .= chr(0x80 | $_C & 0x3F); }elseif($_C >18); $_String .= chr(0x80 | $_C>>12 & 0x3F); $_String .= chr(0x80 | $_C>>6 & 0x3F); $_String .= chr(0x80 | $_C & 0x3F); } return iconv('UTF-8', 'GB2312', $_String); } //测试 echo Pinyin('中文字','gb2312'); //第二个参数“1”可随意设置即为utf8编码 ?>
上一篇: php获取字符串uft-8编码
下一篇: php session 写入数据库