如何在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; } ?> 做网站,找巨腾!(点击一下,惊喜无限) 想买个这个OA系统,大家觉得怎么样? php如何抓取网页中的数据? 请版主xuzuning大人进来:jpgraph路径. 大家给我推荐个PHP的Blog程序啊 关于memcached,不够再加分 您 想学Erlang吗 大家一起学! thinkPHP无法加载数据库驱动PDO phpcms怎么深入学??? thinkPHP中的select提交表单时遇到的问题 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;
}
?>