富文本内容截取摘要



自动获取富文本摘要有以下几步:

1、使用strip_tags清除富文本中的html和css标签 

2、使用htmlspecialchars_decode内容解码

3、使用mb_substr函数截取指定的长度


public function getPostAbstractAttr()
{
    $excerpt = $this->getAttr('post_excerpt');

    $abstract = mb_substr(strip_tags(htmlspecialchars_decode($this->getAttr('post_content'))), 0, 150);

    $content = !empty($excerpt) ? $excerpt :  $abstract;

    $content = str_replace(' ', '', $content);
    $w = input('w');

    return str_replace($w, "<span style='background-color: #66d9ef'>{$w}</span>", $content);
}



发布时间 : 2023-03-01,阅读量:1068
本文链接:https://upwqy.com/details/409.html
php中常用的魔术方法 Mysql 数据类型