摘要:如题源码第一个字节判断通过第二个字节判断通过第一个字节判断通过第二个字节判断通过湖北武汉北上广火影获得运行结果
如题 - 源码
</>复制代码
= "5.0") ? array_combine ( $_TDataKey, $_TDataValue ) : $this->_Array_Combine( $_TDataKey, $_TDataValue );
arsort ( $data );
reset ( $data );
$str = $this->safe_encoding ( $str );
$_Res = "";
for($i = 0; $i < strlen ( $str ); $i ++) {
$_P = ord ( substr ( $str, $i, 1 ) );
if ($_P > 160) {
$_Q = ord ( substr ( $str, ++ $i, 1 ) );
$_P = $_P * 256 + $_Q - 65536;
}
$_Res .= $this->_Pinyin ( $_P, $data ).$pix;
}
return preg_replace ( "/[^a-z0-9".$pix."]*/", "", $_Res );
}
private function _Pinyin($_Num, $_Data) {
if ($_Num > 0 && $_Num < 160)
return chr ( $_Num );
elseif ($_Num < - 20319 || $_Num > - 10247)
return "";
else {
foreach ( $_Data as $k => $v ) {
if ($v <= $_Num)
break;
}
return $k;
}
}
public function getFirstChar($str=""){
if( !$str ) return null;
$fchar=ord($str{0});
if($fchar>=ord("A") and $fchar<=ord("z") )return strtoupper($str{0});
$s= $this->safe_encoding($str);
$asc=ord($s{0})*256+ord($s{1})-65536;
if($asc>=-20319 and $asc<=-20284)return "A";
if($asc>=-20283 and $asc<=-19776)return "B";
if($asc>=-19775 and $asc<=-19219)return "C";
if($asc>=-19218 and $asc<=-18711)return "D";
if($asc>=-18710 and $asc<=-18527)return "E";
if($asc>=-18526 and $asc<=-18240)return "F";
if($asc>=-18239 and $asc<=-17923)return "G";
if($asc>=-17922 and $asc<=-17418)return "H";
if($asc>=-17417 and $asc<=-16475)return "J";
if($asc>=-16474 and $asc<=-16213)return "K";
if($asc>=-16212 and $asc<=-15641)return "L";
if($asc>=-15640 and $asc<=-15166)return "M";
if($asc>=-15165 and $asc<=-14923)return "N";
if($asc>=-14922 and $asc<=-14915)return "O";
if($asc>=-14914 and $asc<=-14631)return "P";
if($asc>=-14630 and $asc<=-14150)return "Q";
if($asc>=-14149 and $asc<=-14091)return "R";
if($asc>=-14090 and $asc<=-13319)return "S";
if($asc>=-13318 and $asc<=-12839)return "T";
if($asc>=-12838 and $asc<=-12557)return "W";
if($asc>=-12556 and $asc<=-11848)return "X";
if($asc>=-11847 and $asc<=-11056)return "Y";
if($asc>=-11055 and $asc<=-10247)return "Z";
return null;
}
function safe_encoding($string) {
$encoding="UTF8";
for($i=0;$i_outEncoding))
return $string;
else{
// var_dump($encoding,$this->_outEncoding,$string);
return iconv($encoding,$this->_outEncoding,$string);
}
}
private function _Array_Combine($_Arr1, $_Arr2){
for($i = 0; $i < count ( $_Arr1 ); $i ++)
$_Res [$_Arr1 [$i]] = $_Arr2 [$i];
return $_Res;
}
}
$pinyin = new Pinyin();
echo $pinyin->getFirstChar("湖北武汉")."
";
echo $pinyin->getPinyin("北上广")."
";
echo $pinyin->getPinyin("火影")."
";
echo $pinyin->getFirstChar("获得")."
";
echo $pinyin->getFirstChar("TOM")."
";
运行结果
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/21104.html
摘要:拼音字符转换图将中文编码成拼音要转换为拼音的字符串返回格式每个字的首字母全拼音字符串字母中文转换到拼音每次处理一个字符待处理字符双字节拼音结果为拼音首字母测试文字结果为全拼音测试文字结果为第一个拼音测试文字 class Pinyin { /** * 拼音字符转换图 * @var array */ private $data = array(...
摘要:规定要反转的字符串。参考文档实现字符串翻转包含中文汉字参考处理汉字官方文档函数最下面给出了支持的方案三用法区别以及之间关系用法如果是非空或非零的值,则返回。若想检测常量是否已设置,可使用函数。 一、foreach 第一题: //1.for循环执行几次 //for($i=0;$i=1;$i++){ // echo $i; //} $i==1条件很成立,死循环 for($i=0;$...
摘要:下面让云服务器网小编带领大家一起研究并学习一下如何批量替换文章中的文字或域名这篇文章吧。如何批量替换wordpress文章中的文字或域名?如果替换修改大量WordPress文章中的相同文字,手动编辑文章修改工作量大,可以用下面的代码实现批量替换,会用到WordPress的操作数据常量$wpdb修改数据库,不需要登录数据库操作。 这篇文章主要为大家展示了如何批量替换WordPres...
阅读 1802·2021-09-26 09:55
阅读 3866·2021-09-22 15:31
阅读 8209·2021-09-22 15:12
阅读 2283·2021-09-22 10:02
阅读 5042·2021-09-04 16:40
阅读 1130·2019-08-30 15:55
阅读 3128·2019-08-30 12:56
阅读 1883·2019-08-30 12:44