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

php如何截取中英文字符串

WBOY
Release: 2016-06-13 10:32:04
Original
828 people have browsed it

很多朋友一直在为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;

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template