7
12
2016
3

PHP中过滤富文本编辑器的标签

在最近的工作中在用ThinkPHP做的后台,管理数据,前台的微信端读取数据。

后台的富文本编辑器是KindEditor,它经常会增加一些标签,特别是字体的标签,这样微信端的样式就会无法控制,很麻烦。

感谢Google,我找到了http://htmlpurifier.org/,不过官网是2015年更新的了,应该不支持PHP7

下载,解压,在Vendor目录下建立HTMLPurifier目录,然后把解压文件的Library文件全部拷进去

在ThinkPHP的控制器方法即可使用

vendor('HTMLPurifier.HTMLPurifier#auto');
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$config->set('HTML.Allowed','p,br,img[src]');
//保留p br img.src标签
$clean_html = $purifier->purify(I('post.postdata'));
Category: php | Tags: php thinkphp | Read Count: 8143
非常棒刚才 说:
2019年11月21日 00:23

采购部vvbcfbv

JSC Result jessore B 说:
2022年8月27日 16:35

Bangladesh Education Board DPE has conducted the class 8th grade of Junior School Certificate Exam and Junior Dakhil Certificate Exam on 1st to 15th November 2022 at all centers in division wise under Ministry of Primary and Mass Education (MOPME), and the class 8th grade terminal examination tests are successfully conducted for all eligible JSC/JDC students for the academic year of 2022. JSC Result jessore Board The Bangladesh government Minister of Secondary Education is going to announce the JSC Result 2022 in student wise for division students in education board wise, and the result documents will be submitted to the Prime Minister of the country after then the result with mark sheet will be announced to public to check the individual result.

Alyssa 说:
2022年12月21日 00:25

There are a few tags that can be used to filter rich text editors in PHP. The most common are the `

` and `

` tags. These tags Vaccine Distribution can be used to filter out all of the other tags in the document except for the text that is contained within them.

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com