preg 替换所有链接
$text = "Clip - http://depositfiles.com/files/8b5560fne Mp3 -
http://letitbit.net/download/4920.adaf494fbe2b15c34a4733f20/Madonna___The_Power_Of_Good_Bye.mp3.html
Madonna - The power of goodbye Your heart is not open, so I must go The spell has been broken...I
loved you so Freedom comes when you learn to let go Creation comes when you learn to say no You were
my lesson I had to learn I was your fortress you had to burn Pain is a warning that something's wrong
I pray to God that it won't be long Do ya wanna go higher? Chorus: There's nothing left to try
There's no place left to hide There's no greater power than the power of good-bye Your heart is not
open, so I must go The spell has been broken...I loved you so You were my lesson I had to learn I was
your fortress Chorus: There's nothing left to lose There's no more heart to bruise There's no greater
power than the power of good-bye Bridge: Learn to say good-bye I yearn to say good-bye Chorus: There's
nothing left to try There's no more places to hide There's no greater power than the power of good-bye
There's nothing left to lose There's no more heart to bruise There's no greater power than the power
of good-bye";
我怎样才能彻底切断本文中的所有链接?
$text = "Clip - http://depositfiles.com/files/8b5560fne Mp3 -
http://letitbit.net/download/4920.adaf494fbe2b15c34a4733f20/Madonna___The_Power_Of_Good_Bye.mp3.html
Madonna - The power of goodbye Your heart is not open, so I must go The spell has been broken...I
loved you so Freedom comes when you learn to let go Creation comes when you learn to say no You were
my lesson I had to learn I was your fortress you had to burn Pain is a warning that something's wrong
I pray to God that it won't be long Do ya wanna go higher? Chorus: There's nothing left to try
There's no place left to hide There's no greater power than the power of good-bye Your heart is not
open, so I must go The spell has been broken...I loved you so You were my lesson I had to learn I was
your fortress Chorus: There's nothing left to lose There's no more heart to bruise There's no greater
power than the power of good-bye Bridge: Learn to say good-bye I yearn to say good-bye Chorus: There's
nothing left to try There's no more places to hide There's no greater power than the power of good-bye
There's nothing left to lose There's no more heart to bruise There's no greater power than the power
of good-bye";
How do I in this text completely cut all links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这样简单的操作:
不过,它会在结果字符串中留下双空格。你可以处理这个问题,但会变得稍微复杂一些。我也不检查删除的文本是否是有效的网址。任何包含 :// 的内容都会被删除。
You could try something simple like this:
It will leave double spaces in the resulting string though. You could handle that, but it would get slightly more complicated. I also don't check if the text removed are valid URLs. Anything containing :// is removed.
一种简单的方法:
将任何以“http”开头且包含非空格字符的字符串替换为空字符串。
这是假设您只获取 http。否则,就不那么天真了(但仍然大多天真):
A naive approach:
Replaces any string that starts with "http" and consists of non-space characters, with an empty string.
This is assuming that you're only getting http. Otherwise, a little less naive (but still mostly naive):