首页  >  文章  >  后端开发  >  PHP将含有中英文ASCII码字符串切割为单字数组_PHP教程

PHP将含有中英文ASCII码字符串切割为单字数组_PHP教程

WBOY
WBOY原创
2016-07-13 17:46:361379浏览

 

  //含有中英文ASCII码字符串切割为单字数组

    //Satan@Author 2011-10-26 

  private function chinesesplit($str){

        //$str="x个小姑娘去kfc吃chicken,飞刀已出手,nobody看到什么时候出手的,Mr'Li手中仍握着那个木雕,但刀已不在noanymore";

        $ascLen=strlen($str);

        for($i;$i

        $c=ord(substr($str,0,1));

        if(ord(substr($str,0,1)) >252){$p = 5;}elseif($c > 248){$p = 4;}elseif($c > 240){$p = 3;}elseif($c > 224){$p = 2;}elseif($c > 192){$p = 1;}else{$p = 0;}

        $truekey=substr($str,0,$p+1);

        if($truekey===false){break;}       

        $splikey[]=$truekey;

        $str=substr($str,$p+1);

        }

        return $splikey;

}

 

摘自 烂在棺材里

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478565.htmlTechArticle//含有中英文ASCII码字符串切割为单字数组 //Satan@Author 2011-10-26 private function chinesesplit($str){ //$str=x个小姑娘去kfc吃chicken,飞刀已出手,nobo...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn