【发布时间】:2020-04-27 18:23:49
【问题描述】:
有点卡住了,是否可以使用 PHP 来更新/更改 html 元素的内容。 因此,根据 id 名称仅替换下面字符串中的“Hello World”。
$html = '<h1 id="item" class="abc" data="efg">Hello World</h1>';
也许使用 preg_replace,只是想将所有其他内容保留在那里,例如。类、数据等
$html = preg_replace('<h1 id="item">????</h1>', 'New Content', $html);
谢谢
【问题讨论】:
-
这能回答你的问题吗? Modify html attribute with php
-
<h1 id="item">!=<h1 id="item" class="abc"你也不应该使用正则表达式来解析 HTML。使用解析器。
标签: php