0
我創建了一個自動檢測鏈接的函數。它工作得很好,除非一個HTML標籤剛好在一個鏈接之後開始(沒有空格)。自動鏈接檢測器(PHP + RegEx)
實施例:
http://www.google.com is cool
變得
<a href="http://www.google.com" target="_blank">www.google.com</a> is cool
但
http://www.google.com<br />is cool
(無空間HTTP後://在真實)變爲
<a href="http://www.google.com<br /" target="_blank">www.google.com<br /</a> is cool
我的正則表達式首先不會停止<
,但不允許<
...
我該如何解決這個問題?或者我怎樣纔能有效地排除<
?
這裏是我的功能:
function detect_linkg($str){
return preg_replace('#(https?://)([\w\d.&:\#@%/;$~_?\+-=]*)#','<a href="$1$2" target="_blank">$2</a>',$str);
}
感謝您的幫助!
謝謝,這就是解決方案! –