前端之家收集整理的这篇文章主要介绍了
php 内容清除html代码的实现方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
经测试代码如下:
/**
* 从可能包含html标记的内容中萃取纯文本摘要
*
* @param string $data
* @param int $len
* @author 编程之家 jb51.cc jb51.cc
*/
function extractHtmlData($data,$len) {
$data = strip_tags(subString($data,$len + 30));
$search = array("/([\r\n])[\s]+/",// 去掉空白字符
"/&(quot|#34);/i",// 替换 HTML 实体
"/&(amp|#38);/i","/&(lt|#60);/i","/&(gt|#62);/i","/&(nbsp|#160);/i","/&(iexcl|#161);/i","/&(cent|#162);/i","/&(pound|#163);/i","/&(copy|#169);/i","/\"/i",);
$replace = array(" ","\"","&"," ","",chr(161),chr(162),chr(163),chr(169),"");
$data = trim(subString(preg_replace($search,$replace,$data),$len));
return $data;
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/529192.html