如何在PHP中去除代码中所有的html标签。 如何在PHP中去除代码中所有的html标签。用正则去除英文的方法就不必说了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 利用strip_tags()就可以把html标签去除掉. 就是楼上说的方法。可参考http://www.w3school.com.cn/php/func_string_strip_tags.asp strip_tags()会去掉标签htmlspecialchars()则会将<>转为 < > <?php function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA ); $text = preg_replace($search, '', $document); return $text; } ?> 急需解决:PHP Session问题-ECSHOP 求php怎么调用含BLOB存储过程 夜深了,还有高手在吗? PHP+flashpaper2.0转换文档时xls后缀的换换失败 有没有能批量上传图片的html编辑器? PHP 模拟登录不功成 PHP函数问题 关于thinkphp 3.2.1的问题 分享一个优秀的编辑器SublimeText2.0.1 php 代码解释 ThinkPHP中应用FCK问题 需要开发一个售票网站,求思路~
htmlspecialchars()则会将<>转为 < >
function html2txt($document){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $document);
return $text;
}
?>