2010-02-16 4 views
0
$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"; 

어떻게하면이 링크에서 모든 링크를 완전히 자르나요?preg 모든 링크 대체

+1

잘라내는 것은 제거한 것을 기억하지 않고 빈 문자열을 완전히 제거하고 바꿉니다. –

답변

3

당신은이 같은 단순한 뭔가를 시도 할 수 있습니다. 당신은 그것을 처리 할 수 ​​있습니다, 그러나 그것은 약간 더 복잡하게 될 것입니다. 또한 제거 된 텍스트가 유효한 URL인지 확인하지 않습니다. 다음을 포함하는 모든 것은 // 제거됩니다.

1

본래의 접근 방식은 :

preg_replace('/http[^\s]+/', "", $str) 

은 빈 문자열로, "HTTP"로 시작하고 공백이 아닌 문자로 구성 문자열을 대체합니다.

이것은 http 만 받고있는 것으로 가정합니다. 그렇지 않으면, 좀 덜 순진 (하지만 여전히 대부분 순진) : 그것은 비록 결과 문자열에 이중 공간을 남겨 둘 것이다

$text = preg_replace("#\S+://\S+#", "", $text); 

:

preg_replace('#[a-z]+://[^\s]+#', "", $str) 
+0

혼동을 피하기 위해 결과를 지정하는 것이 좋습니다. SO에 대한 일반적인 질문은 '대체 방법으로는 아무 것도하지 않는 이유가 무엇입니까?'입니다. 또는 그 주제의 변형. –

+0

아, 좋은 지적이야. 팁 주셔서 감사합니다 :) –

관련 문제