Home  >  Article  >  php教程  >  php如何截取中英文字符串

php如何截取中英文字符串

WBOY
WBOYOriginal
2016-06-13 10:32:04794browse

很多朋友一直在为php(做为现在的主流开发语言)中如何截取中英文字符串而苦恼,我一直在用该方法,大家不妨试试看。

function str_cut($str_cut,$length){

    if(strlen($str_cut) > $length){   //处理标题,太长用……表示
       for($i=0; $i            if (ord($str_cut[$i]) > 128) $i++;
       }
       $str_cut = substr($str_cut,0,$i);
   }
   return $str_cut;
}


$content="艰苦电加fgfgfh工搭街jhkjlk坊扛大;l;l个艰苦法fdfd国家igkdjgkfdg…………………………";

$content=str_cut($content,$length="25");

echo $content;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn