// 无格式转换
function ClearHtml($content,$allowtags='') {

mb_regex_encoding('UTF-8');
//replace MS special characters first
$search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u');
$replace = array('\'', '\'', '"', '"', '-');
$content = preg_replace($search, $replace, $content);
//make sure _all_ html entities are converted to the plain ascii equivalents - it appears
//in some MS headers, some html entities are encoded and some aren't
$content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
//try to strip out any C style comments first, since these, embedded in html comments, seem to
//prevent strip_tags from removing html comments (MS Word introduced combination)
if(mb_stripos($content, '/*') !== FALSE){
$content = mb_eregi_replace('#/\*.*?\*/#s', '', $content, 'm');
}
//introduce a space into any arithmetic expressions that could be caught by strip_tags so that they won't be
//'<1' becomes '< 1'(note: somewhat application specific)
$content = preg_replace(array('/<([0-9]+)/'), array('< $1'), $content);

$content = strip_tags($content, $allowtags);
//eliminate extraneous whitespace from start and end of line, or anywhere there are two or more spaces, convert it to one
$content = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $content);
//strip out inline css and simplify style tags
$search = array('#<(strong|b)[^>]*>(.*?)</(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)</(em|i)>#isu', '#<u[^>]*>(.*?)</u>#isu');
$replace = array('<b>$2</b>', '<i>$2</i>', '<u>$1</u>');
$content = preg_replace($search, $replace, $content);

//on some of the ?newer MS Word exports, where you get conditionals of the form 'if gte mso 9', etc., it appears
//that whatever is in one of the html comments prevents strip_tags from eradicating the html comment that contains
//some MS Style Definitions - this last bit gets rid of any leftover comments */
$num_matches = preg_match_all("/\<!--/u", $content, $matches);
if($num_matches){
$content = preg_replace('/\<!--(.)*--\>/isu', '', $content);
}
return $content;
}
//
echo ClearHtml($content,'<p>');

最新文章

  1. 【转】Myeclipse建立Maven项目
  2. IOS 网络浅析(一 网络监测~Reachability)
  3. 【转】The decoupling capacitor…is it really necessary?
  4. ios基础篇(七)——UISwich、UISlider、UIProgressView的用法总结
  5. sshj ,ssh , springmvc pom.xml
  6. (翻译)什么是Java的永久代(PermGen)内存泄漏
  7. 【MongoDB】windows平台搭建Mongo数据库复制集(相似集群)(一)
  8. 一台服务器上同时启动多个 Tomcat
  9. OD常用断点之CC断点
  10. python爬虫(四)_urllib2库的基本使用
  11. BZOJ 4555: [Tjoi2016&amp;Heoi2016]求和 [分治FFT 组合计数 | 多项式求逆]
  12. 拦截请求并记录相应信息-springboot
  13. Qt3D
  14. GridView的stretchMode属性
  15. linux下的环境变量配置
  16. [Web 前端] 流行的JavaScript库 ——jQuery
  17. linux命令大全网站
  18. WireShark 基本介绍
  19. Linux查看GPU信息和使用情况
  20. elasticsearch安装与使用(6)-- Logstash安装与配置

热门文章

  1. CSS3背景渐变。。。
  2. redis 安装方式
  3. C# 控件拖动
  4. SQL SERVER 审核
  5. Nginx集群之SSL证书的WebApi身份验证
  6. TPYBoard实例之利用WHID为隔离主机建立隐秘通道
  7. 如何压缩UUID长度?
  8. sql server存储过程实现批量删除
  9. 001_JS基础_JavaScript简介
  10. DAY4-打卡第四天-2018-1-12