简体   繁体   English

<a>从HTML中</a>删除<a>标记</a>

[英]Remove <a> tag from HTML

I'd like to remove the tag from my HTML. 我想从HTML中删除标记。

I have the following HTML: <h1><a href="http://www.google.com/">Google</a>& Yahoo</h1> 我有以下HTML: <h1><a href="http://www.google.com/">Google</a>& Yahoo</h1>

I'd like to use PHP to convert the above to: <h1>& Yahoo</h1> 我想使用PHP将上述内容转换为: <h1>& Yahoo</h1>

Can someone explain how I achieve this? 有人能解释我是如何做到这一点的吗

You can do this with strip_tags() . 你可以用strip_tags()来做到这一点。

strip_tags('<h1><a href="http://www.google.com/">Google</a>& Yahoo</h1>', '<h1>');

The result will be <h1>Google & Yahoo</h1> . 结果将是<h1>Google & Yahoo</h1> In case you really want the result <h1>& Yahoo</h1> , you can do it in this way: 如果你真的想要结果<h1>& Yahoo</h1> ,你可以这样做:

preg_replace("@<a[^>]*?>.*?</a>@si", '', '<h1><a href="http://www.google.com/">Google</a>& Yahoo</h1>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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