Convert HTML to text// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<style[^>]*?>.*?</style>'si", // Strip out css
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php$replace = array ("",
"",
"\\1",
"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");$text = preg_replace ($search, $replace, $document);
解决方案 »
- 一般拼字符串用哪种方式呀
- 我是个新手想多学习PHP谁能给我一本这方面入门级别的书啊。。。
- Fatal error: Call to a member function GetArray() on a non-object
- 菜鸟求解?做一个手机软件下载时选择机型的设置,该怎么办?谁又会?可以支付报酬
- 初学Memcache,问个更新点击量的问题
- 路径为“/”,为什么找到的是workspacing的上一层?
- 如何实现网站内的一个指定网页同时只有一个用户可以访问?
- 怎样让一个td里前面的文字和textarea的最高平齐?
- get 何 post有何区别?
- 有没有自学PHP或者JAVA等等的大神。 指条明路! 谢谢啦!
- 关于“filename.php?mess_id=123”类型描述的问题
- php中能象vc中样创建线程吗?
preg_replace( "#<script.*?>.+?<\/script>#is", "", $str );
//去掉style
preg_replace( "#<style>.+?<\/style>#is", "", $str );然后再strip_tags()...