当前位置:Gxlcms > PHP教程 > php清理word产生的html的函数

php清理word产生的html的函数

时间:2021-07-01 10:21:17 帮助过:17人阅读

在使用FCKedior或ueditor时,从word中粘贴过来的内容,会产生很多额外的标签,本文分享一个清理这种多出的html代码的函数,有需要的朋友参考下。

说明: 使用FCKedior或ueditor时,从word中粘贴过来的,会产生好多额外的标签。 本节分享一例代码,用于清除word产生的html代码。 例子:


') { mb_regex_encoding('UTF-8'); $search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u'); $replace = array('\'', '\'', '"', '"', '-'); $text = preg_replace($search, $replace, $text); $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); if(mb_stripos($text, '/*') !== FALSE){ $text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm'); } $text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text); $text = strip_tags($text, $allowed_tags); $text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $text); $search = array('#<(strong|b)[^>]*>(.*?)#isu', '#<(em|i)[^>]*>(.*?)#isu', '#]*>(.*?)
#isu'); $replace = array('$2', '$2', '$1'); $text = preg_replace($search, $replace, $text); $num_matches = preg_match_all("/\