如何使用php querypath从html中删除锚标签

时间:2012-12-20 05:52:14

标签: php html-parsing querypath

我正在使用php Querypath,我正在尝试从html中删除特定href的锚标签。

例如

<html>
<body>
   <div>
      <a  href="#down"></a>
      <a href="#top" ><img src="img.png" /> </a>
      <a href="#top" ><img src="img.png" /> </a>
   </div>
</body>
</html>

我的输出应该是

<html>
<body>
   <div>
      <a  href="#down"></a>
   </div>
</body>
</html>

应删除带有href top的锚点。

我尝试使用以下代码

$html = qp($html)->find("a#top")->remove()->writeHTML();

但它没有移除以下锚点。

请让我知道如何在php查询路径中实现此目的。

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

这将删除href=top的锚标记。

$("a[href^=#top]").remove();
相关问题