工作中可能用到,嘎嘎
<?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;