php - 使用 php 删除内联样式

标签 php inline styles

<分区>

我正在使用 php 输出一些富文本。我怎样才能完全去除内联样式?

文本将直接从 MS Word 或 OpenOffice 中粘贴到使用 TinyMCE 的软件中,TinyMCE 是一种富文本编辑器,可让您向文本添加基本的 HTML 格式。 但是我想删除

标签上的内联样式(见下文),但保留

标签本身。

<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. &ldquo;Sorry.&rdquo; She said, breathing warm air onto the shy man's neck. Rufus trembled.</p>
<p style="margin-bottom: 0cm;">&nbsp;</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. &ldquo;Most of these apes seem to be dying, but you might need this, just to give them a helping hand.&rdquo;</p>

最佳答案

我很快就把它放在一起了,但是对于“内联样式”(!)你需要类似的东西

$text = preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $text);

关于php - 使用 php 删除内联样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2488950/

相关文章:

php - 从 symfony 3.4 迁移到 symfony 4

php - 如何将波斯语/阿拉伯语数字从字符串转换为英语数字?

html - CSS IE6 向右浮动

c++ - C++ 链接器是否会自动内联函数(没有 "inline"关键字,在 header 中没有实现)?

php - 在为文档编写注释头时,如何指定该函数返回另一个函数?

javascript - React - 组件样式未从 Prop 更新

php - 从一个表中选择多个数据并使用PHP表单插入到另一个表中

php - 记录计数为零时重定向页面

c++ - 在 cpp 项目 (VS2005) 中编译的 c 模块中无法识别内联关键字

c# - 让文本与 TextBlock 的顶部齐平(不是 VerticalAlignment,我保证!)