简体   繁体   中英

How to remove anchors tags from html using php querypath

I'm working with php Querypath and I'm trying to remove anchor tags with particular href from html.

for example

<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>

my output should be

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

Anchors with href top should be removed.

I tried with following Code

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

But it didn't remove following anchors.

Please let me know how to achieve this in php query path.

Thanks a lot for the help.

这将删除带有href=top锚标记。

$("a[href^=#top]").remove();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM