PHP清除html代码
//php去除所有html代码,留下的全部是文字,不使用html样式等.,这个是朋友发的,具体来源不详. www.forasp.cn 整理
//去除所有html代码
function replaceHtmlAndJs($document)
{
$document = trim($document);
if (strlen($document) <= 0)
{
return $document;
}
$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 javascript
"'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'([\r\n])[\s]+'", // 去掉空白字符forasp.cn整理
"'&(quot|#34);'i", // 替换 HTML 实体
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"\"",
"\'",
); // 作为 PHP 代fo码asp运.行cn
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
" ",
" "
);
return @preg_replace ($search, $replace, $document);
}
网站制作学习网.http://www.forasp.cn 整理,来源不详.