我想要移除所有标签属性,除了src
属性。例如:
<p id="paragraph" class="green">This is a paragraph with an image <img src="/path/to/image.jpg" width="50" height="75"/></p>
将被返回为:
<p>This is a paragraph with an image <img src="/path/to/image.jpg" /></p>
我有一个正则表达式可以去除所有属性,但我想调整它以保留src
。这是我目前的代码:
<?php preg_replace('/<([A-Z][A-Z0-9]*)(\b[^>]*)>/i', '<$1>', '<html><goes><here>');