如何删除链接并保留文本?
text text text. <br><a href='http://www.example.com' target='_blank' title='title' style='text-decoration:none;'>name</a>
像这样:
text text text. <br>
我还有一个问题......
$text = file_get_contents('http://www.example.com/file.php?id=name');
echo preg_replace('#<a.*?>.*?</a>#i', '', $text)
在该 url 中是该文本(带有链接)...
此代码无效...
怎么了?
有人可以帮助我吗?
最佳答案
我建议您将文本保留在链接中。
strip_tags($text, '<br>');
或者困难的方法:
preg_replace('#<a.*?>(.*?)</a>#i', '\1', $text)
如果您不需要在链接中保留文字
preg_replace('#<a.*?>.*?</a>#i', '', $text)
关于php - 如何从 php 中的内容中删除链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3830717/