php教程

超轻量级php框架startmvc

php简单截取字符串代码示例

更新时间:2020-03-13 09:43:17 作者:startmvc
本文实例讲述了php简单截取字符串的方法。分享给大家供大家参考,具体如下://截取摘要p

本文实例讲述了php简单截取字符串的方法。分享给大家供大家参考,具体如下:


//截取摘要
public static function mbsubstr($str){
 $strleng = mb_strlen($str,"utf8");
 $mbstr = mb_substr($str,0,140,'utf8');
 $strdstr = mb_substr($str,140,$strleng,'utf8');
 $strlengs = mb_strlen($strdstr,'utf8');
 $strc = "";
 for($i=0;$i<$strlengs;$i++){
 $strn = mb_substr($strdstr,$i,1,'utf8');
 if($strn == "。" || $strn == "?" || $strn == "!"){
 break;
 }
 $strc .= $strn;
 }
 $strd = $mbstr.$strc;
 //echo $strleng."@".mb_strlen($strd,'utf8')."@".$strd."<br>";
 return $strd;
}

php 截取 字符串