I am new to PHP and trying to replace a URL pattern with google.com in the code below.
$textStr = "Test string contains http://foo.com/more_(than)_one_(parens)
http://foo.com/blah_(wikipedia)#cite-1
http://foo.com/blah_(wikipedia)_blah#cite-1
http://foo.com/unicode_(?)_in_parens
http://foo.com/(something)?after=parens
more urls foo.ca/me some other text";
$pattern = '(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)((?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))*)';
$textStr = preg_replace($pattern, "google.com", $textStr);
echo $textStr;
I found the regular expression pattern at http://daringfireball.net/2010/07/improved_regex_for_matching_urls but I have not been able to escape the single quote, double quotes in the pattern successfully.
Currently I get the message -- Warning: preg_replace() Unknown modifier '\' But I used the slash() to escape the single quote in {};:\'"
Can someone please help me with the code above?