工作中可能用到,嘎嘎
<?php
/**
* @Describe: 中文转化为英文首字母 中国:ZG ;中2国:ZG;z国:ZG
* 1:省略了数字
* 2:空格,tab符,不能识别的字符一律返回null,即去除, wo是 中国:woszg
* ...
*/
class Character{
/**
* @param $string
* @param int $length 转化的长度
*
* @return bool|string
*/
public static function getEnByCnByString($string, $length=10){
if(empty($string)){return false;}
preg_match_all("/./u", $string, $arr);
$exp =$arr[0];
if(empty($exp)){return false;}
$sum =1;
$res ='';
foreach ($exp as $key=>$value){
$cha = self::getFirstCharter($value);
$res.=$cha;
if(!empty($cha)){
$sum++;
}
if($sum >$length){
return $res;
}
}
return $res;
}
/**
* 转化中文为字母的工具
* @param $str
* @return null|string
*/
public static

本文介绍了在工作中如何使用PHP来获取中文字符对应的拼音首字母,这对于处理中文数据时进行编码或者搜索等操作非常有用。
最低0.47元/天 解锁文章
250

被折叠的 条评论
为什么被折叠?



