我正在使用php输出一些富文本。怎样才能完全去掉内联样式呢?
文本将直接从MS Word或OpenOffice中粘贴出来,然后粘贴到使用TinyMCE的文本编辑器中。但是,我想要删除
标记(见下文),但保留
标签本身。
<p style="margin-bottom: 0cm;">A patrol of Zograth apes came round the corner, causing Rosette to pull Rufus into a small alcove, where she pressed her body against his. “Sorry.” She said, breathing warm air onto the shy man's neck. Rufus trembled.</p>
<p style="margin-bottom: 0cm;"> </p>
<p style="margin-bottom: 0cm;">Rosette checked the coast was clear and pulled Rufus out of their hidey hole. They watched as the Zograth walked down a corridor, almost out of sight and then collapsed next to a phallic fountain. As their bodies hit the ground, their guns clattered across the floor. Rosette stopped one with her heel and picked it up immediately, tossing the other one to Rufus. “Most of these apes seem to be dying, but you might need this, just to give them a helping hand.”</p>发布于 2010-03-23 07:29:17
我很快就把这些放到了一起,但是对于‘内联样式’(!)你需要像这样的东西
$text = preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $text);发布于 2013-12-07 04:04:07
这是我从克罗津的答案中得出的一个preg_replace解决方案。它允许在style属性之前和之后使用属性来修复锚点标签的问题。
$value = preg_replace('/(<[^>]*) style=("[^"]+"|\'[^\']+\')([^>]*>)/i', '$1$3', $value);发布于 2010-03-22 18:14:51
使用HtmlPurifier
https://stackoverflow.com/questions/2488950
复制相似问题