本篇文章给大家带来了关于php的相关知识,其中主要跟大家介绍php怎么获取标题的拼音首字母,有代码示例,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

获取标题的拼音首字母
这里需要注意的是 x 的 ascii 值的区间,有可能会出现判断为空的情况,已做修改。
一、通过计算 ascii 码值对比字母的 ascii 码值得出。
public function getfirstchar($s0)
{
$fchar = ord($s0{0});
if($fchar >= ord("A") and $fchar = -20319 and $asc = -20283 and $asc = -19775 and $asc = -19218 and $asc = -18710 and $asc = -18526 and $asc = -18239 and $asc = -17922 and $asc = -17922 and $asc = -17417 and $asc = -16474 and $asc = -16212 and $asc = -15640 and $asc = -15165 and $asc = -14922 and $asc = -14914 and $asc = -14630 and $asc = -14149 and $asc = -14090 and $asc = -13318 and $asc = -12838 and $asc = -22605 and $asc = -11847 and $asc = -11055 and $asc <p>二。获取整个标题的拼音首字母</p><pre class="brush:php;toolbar:false"> public function pinyin_long($zh)
{
$ret = "";
if(empty($zh))
{
$ret="x";
}else{
$s1 = mb_convert_encoding($zh,"GBK","UTF-8");
$s2 = mb_convert_encoding($s1,"UTF-8","GBK");
if($s2 == $zh){$zh = $s1;}
for($i = 0; $i 160){
$s2 = substr($zh,$i++,2);
$ret .= $this->getfirstchar($s2);
}else{
$ret .= $s1;
}
}
}
return $ret;
}推荐学习:《PHP视频教程》
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!











