想更換所有出現時雙引號包含php:如何正則表達式替換下面的字符串?
"http://somebunchofchar"
到
"link"
我想出了preg_replace("/\"http:\/\/.\"/i", "\"link\"", $string);
想更換所有出現時雙引號包含php:如何正則表達式替換下面的字符串?
"http://somebunchofchar"
到
"link"
我想出了preg_replace("/\"http:\/\/.\"/i", "\"link\"", $string);
只需點後添加一個星號和問號
preg_replace("/\"http:\/\/.*?\"/i", "\"link\"", $string);
請看這裏: http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2&AspxAutoDetectCookieSupport=1 如何匹配具有正確模式的URL;不是使用preg_replace函數與特定的正則表達式模式;-)(你可以在開始添加這些報價並結束該模式自己很容易):-)
$string = preg_replace('#"http://.+"#', '"link"', $string);
您可以使用:
preg_replace('~"http://[^"]*"~i', '"link"', $string);
HTTP ://stackoverflow.com/questions/1188129/replace-urls-in-text-with-html-links – 2012-01-27 08:09:41