php截取中文字符串

/**
 * 截取中文字符串
 * @param $content 需要处理的内容
 * @param $lengh 长度
 * @return $text 返回的内容
 */
public static function subText($content, $lengh = 100){

    $content = htmlspecialchars_decode($content);

    $text = str_replace([" "],'',$content);

    $text = str_replace(["
"
,"
"
],'\n',$text); $text = strip_tags($text); if(mb_strlen($text) > $lengh){ $text = mb_substr($text,0,$lengh,'utf-8'); $text .='......'; } $text = str_replace(['\n'],'',$text); return $text; }

你可能感兴趣的:(php)