净化内容 关键词

xh   ·   发表于 2022-9-5   ·   技术交流

有时候采集没设置好,什么乱七八糟的文字垃圾都有...

所以我们需要净化给读者看着舒服。

ky_config 数据表里添加以下


找到application/common/model/Api.php文件

Api.php里查找

private function change_chapter_content

进行替换一下

private function change_chapter_content($content){

$content = str_ireplace(['<br>','<br\/>','<br />',' ','&nbsp;','<p>','</p>','<p/>'], ["\r\n","\r\n","\r\n","","","","\r\n","\r\n"], $content);

$content_arrays = preg_split('/[\r\n]+/', trim($content,"\r\n"));

 

//   内容替换为空

        $neirong_key = preg_split('/[\r\n]+/', trim(Config::get('web.neirong_key'), "\r\n"));

        $content_array = str_replace($neirong_key, '', $content_arrays);

if(is_array($content_array)){

if(!$this->api_url){

$map = ['status'=>1,'group'=>'chapter_content'];

         $addons_name = Db::name('Addons')->where($map)->value('name');

         $addons_class = get_addon_class($addons_name);

            if(class_exists($addons_class)){

                $addon = new $addons_class();

                $content_array=$addon->run($content_array);

            }

}

$content = '';

foreach ($content_array as $value) {

     if($value){

$content.='<p>  '.$value.'</p>';

}

     }

      

}

//<p>  P中文空格2+关键词如符号听书带符号换行无法阅读</p>


 $neirong2_key = preg_split('/[\r\n]+/', trim(Config::get('web.neirong_key'), "\r\n"));

        $contentb = str_replace($neirong2_key, '', $content);

return $contentb;

}

替换两种格式




5 条回复   |  直到 9个月前 | 367 次浏览

xh
发表于 2022-9-5


净化结果

评论列表

  • 加载数据中...

编写评论内容

xiaoshuo88
发表于 2022-9-6

感谢分享,楼主这个应该是在读取到前端的时候做的全局替换,存储的原文不做改变。


采集规则里面也有正文替换的设置来着,可以针对每个源做不同的过滤,顺便我之前发过让采集规则内容支持正则替换的方法,如果熟悉正则的话也可以尝试那个,让过滤更强大。

评论列表

  • 加载数据中...

编写评论内容

xh
发表于 2022-9-6

xiaoshuo88

2022-9-6

感谢分享,楼主这个应该是在读取到前端的时候做的全局替换,存储的原文不做改变。


采集规则里面也有正文替换的设置来着,可以针对每个源做不同的过滤,顺便我之前发过让采集规则内容支持正则替换的方法,如果熟悉正则的话也可以尝试那个,让过滤更强大。

这是 后期处理,原文不变。APP 和网站都有效!

评论列表

  • 加载数据中...

编写评论内容

41792646
发表于 9个月前

这个是不是用不了了我试了发现提示语法错误

评论列表

  • 加载数据中...

编写评论内容

xh
发表于 9个月前

41792646

9个月前

这个是不是用不了了我试了发现提示语法错误

可以呀  一直在用

评论列表

  • 加载数据中...

编写评论内容
登录后才可发表内容