Is it possible to remove all <a>
tags / links from strings while keeping the content? strip_tags
is not an option, because there are <p>
tags in it which I want to keep. The links are structured this way:
<a style="color: #000000" href="{url}">***content***</a>
答案 0 :(得分:1)
strip_tags方法接受第二个可选参数,标签不能删除。
http://php.net/manual/en/function.strip-tags.php
来自Php.net的例子:
<?php $text = '<p>Test paragraph.</p><!-- Comment --> <a ref="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
The above example will output:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>