我想從一個純文本字符串在PHP中提取一個或多個網址。下面是一些例子從一個字符串提取一個或多個網址在php
"mydomain.com has hit the headlines again"
提取物 「http://www.mydomain.com」
"this is 1 domain.com and this is anotherdomain.co.uk but sometimes http://thirddomain.net"
提取物 「http://www.domain.com」, 「http://www.anotherdomain.co.uk」, 「http://www.thirddomain.net」
有兩種特殊情況下,我需要的 - 我想正則表達式,但不完全瞭解它們
1)需要刪除像'('或')'和空格(不包括連字符)的所有符號
)字點需要用符號替換。 ,所以網絡com將.com .com
p.s我知道PHP validation/regex for URL,但不能解決我將如何使用它來實現最終目標。
謝謝
'mydomain.com = HTTP:// www.mydomain.com' – NikiC 2010-11-06 09:36:52