如何从PHP中的内容中删除链接? [英] How to remove a link from content in php?
本文介绍了如何从PHP中的内容中删除链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何删除链接并保留文本?
How can i remove the link and remain with the text?
text text text. <br><a href='http://www.example.com' target='_blank' title='title' style='text-decoration:none;'>name</a>
像这样:
text text text. <br>
我还有问题.....
i still have a problem.....
$text = file_get_contents('http://www.example.com/file.php?id=name');
echo preg_replace('#<a.*?>.*?</a>#i', '', $text)
在该网址中是该文字(带链接)...
in that url was that text(with the link) ...
此代码不起作用。 ..
this code doesn't work...
出了什么问题?
有人能帮帮我吗?
推荐答案
我建议您将文本保留在链接中。
I suggest you to keep the text in link.
strip_tags($text, '<br>');
或困难的方式:
preg_replace('#<a.*?>(.*?)</a>#i', '\1', $text)
如果您不需要在链接中保留文字
If you don't need to keep text in the link
preg_replace('#<a.*?>.*?</a>#i', '', $text)
这篇关于如何从PHP中的内容中删除链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文