php讀取富文字編輯器編輯後的文章內容,並去除所有html標籤、空格以及空白,擷取字串(包括中文)
阿新 • • 發佈:2019-02-05
/**
* 去除Html所有標籤、空格以及空白,並擷取字串(包括中文)
* @param string $string 字串
* @param number $sublength 字串長度
* @param string $encoding 編碼方式
* @param string $ellipsis 省略號
*/
function cutstr_html($string, $sublength = 230, $encoding = 'utf-8', $ellipsis = '…'){
$sublen ;
$string = strip_tags($string);
$string = trim($string);
$string = ereg_replace("\t","",$string);
$string = ereg_replace("\r\n","",$string);
$string = ereg_replace("\r","",$string);
$string = ereg_replace("\n","",$string);
$string = ereg_replace(" ","",$string);
if(mb_strlen(trim($string),'utf-8') < 230){
return trim($string).$ellipsis;
}else{
return mb_strcut(trim($string),0,$sublength,$encoding).$ellipsis;
}
* 去除Html所有標籤、空格以及空白,並擷取字串(包括中文)
* @param string $string 字串
* @param number $sublength 字串長度
* @param string $encoding 編碼方式
* @param string $ellipsis 省略號
*/
function cutstr_html($string, $sublength = 230, $encoding = 'utf-8', $ellipsis = '…'){
$sublen ;
$string = strip_tags($string);
$string = trim($string);
$string = ereg_replace("\t","",$string);
$string = ereg_replace("\r\n","",$string);
$string = ereg_replace("\r","",$string);
$string = ereg_replace("\n","",$string);
$string = ereg_replace(" ","",$string);
if(mb_strlen(trim($string),'utf-8') < 230){
return trim($string).$ellipsis;
}else{
return mb_strcut(trim($string),0,$sublength,$encoding).$ellipsis;
}
}
注意:使用mb_strcut()時需要開啟php_mbstring.dll擴充套件檔案