• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 获得汉字拼音首字母的函数_php技巧

php 搞代码 4年前 (2022-01-26) 22次浏览 已收录 0个评论

php获取汉字拼音的第一个字母

<?php <BR>function getinitial($str) <BR>{ <BR>$asc=ord(substr($str,0,1)); <BR>if ($asc<160) //非中文 <BR>{ <BR>if ($asc>=48 && $asc<=57){ <BR>return '1'; //数字 <BR>}elseif ($asc>=65 && $asc<=90){ <BR>return chr($asc); // A--Z <BR>}elseif ($asc>=97 && $asc<=122){ <BR>return chr($asc-32); // a--z <BR>}else{ <BR>return '~'; //其他 <BR>} <BR>} <BR>else //中文 <BR>{ <BR>$asc=$asc*1000+ord(substr($str,1,1)); <BR>//获取拼音首字母A--Z <BR>if ($asc>=176161 && $asc<176197){ <BR>return 'A'; <BR>}elseif ($asc>=176197 && $asc<178193){ <BR>return 'B'; <BR>}elseif ($asc>=178193 && $asc<180238){ <BR>return 'C'; <BR>}elseif ($asc>=180238 && $asc<182234){ <BR>return 'D'; <BR>}elseif ($asc>=182234 && $asc<183162){ <BR>return 'E'; <BR>}elseif ($asc>=183162 && $asc<184193){ <BR>return 'F'; <BR>}elseif ($asc>=184193 && $asc<185254){ <BR>return 'G'; <BR>}elseif ($asc>=185254 && $asc<187247){ <BR>return 'H'; <BR>}elseif ($asc>=187247 && $asc<191166){ <BR>return 'J'; <BR>}elseif ($asc>=191166 && $asc<192172){ <BR>return 'K'; <BR>}elseif ($asc>=192172 && $asc<194232){ <BR>return 'L'; <BR>}elseif ($asc>=194232 && $asc<196195){ <BR>return 'M'; <BR>}elseif ($asc>=196195 && $asc<197182){ <BR>return 'N'; <BR>}elseif ($asc>=197182 && $asc<197190){ <BR>return 'O'; <BR>}elseif ($asc>=197190 && $asc<198218){ <BR>return 'P'; <BR>}elseif ($asc>=198218 && $asc<200187){ <BR>return 'Q'; <BR>}elseif ($asc>=200187 && $asc<200246){ <BR>return 'R'; <BR>}elseif ($asc>=200246 && $asc<203250){ <BR>return 'S'; <BR>}elseif ($asc>=203250 && $asc<205218){ <BR>return 'T'; <BR>}elseif ($asc>=205218 && $asc<206244){ <BR>return 'W'; <BR>}elseif ($asc>=206244 && $asc<209185){ <BR>return 'X'; <BR>}elseif ($asc>=209185 && $asc<212209){ <BR>return 'Y'; <BR>}elseif ($asc>=212209){ <BR>return 'Z'; <BR>}else{ <BR>return '~'; <BR>} <BR>} <BR>} <BR>echo getinitial("脚本"); <BR>?><BR>
function getfirstchar($s0){ <BR>$firstchar_ord=ord(strtoupper($s0{0})); <BR>if (($firstchar_ord>=65 and $firstchar_ord=48 and $firstchar_ord<=57)) return $s0{0}; <BR>$s=iconv("UTF-8","gb2312", $s0); <BR>$asc=ord($s{0})*256+ord($s{1})-65536; <BR>if($asc>=-20319 and $asc<=-20284)return "A"; <BR>if($asc>=-20283 and $asc<=-19776)return "B"; <BR>if($asc>=-19775 and $asc<=-19219)return "C"; <BR>if($asc>=-19218 and $asc<=-18711)return "D"; <BR>if($asc>=-18710 and $asc<=-18527)return "E"; <BR>if($asc>=-18526 and $asc<=-18240)return "F"; <BR>if($asc>=-18239 and $asc<=-17923)return "G"; <BR>if($asc>=-17922 and $asc<=-17418)return "H"; <BR>if($asc>=-17417 and $asc<=-16475)return "J"; <BR>if($asc>=-16474 and $asc<=-16213)return "K"; <BR>if($asc>=-16212 and $asc<=-15641)return "L"; <BR>if($asc>=-15640 and $asc<=-15166)return "M"; <BR>if($asc>=-15165 and $asc<=-14923)return "N"; <BR>if($asc>=-14922 and $asc<=-14915)return "O"; <BR>if($asc>=-14914 and $asc<=-14631)return "P"; <BR>if($asc>=-14630 and $asc<=-14150)return "Q"; <BR>if($asc>=-14149 and $asc<=-14091)return "R"; <BR>if($asc>=-14090 and $asc<=-13319)return "S"; <BR>if($asc>=-13318 and $asc<=-12839)return "T<p>4本文¥来源gao!%daima.com搞$代*!码$网9</p><pre>搞代gaodaima码

“;
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;
}
echo getfirstchar(“哈哈”);


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 获得汉字拼音首字母的函数_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址