I want to add GET parameter to all URLs in special string (like html content of a website) .
For example :
Before:
$content = '... <a href="http://foo.bar/register.php">register </a> ... <a href="http://foo.bar/login.php?t=1">login</a> ...';
After:
$content = '... <a href="http://foo.bar/register.php?wid=${wid}">register </a> ... <a href="http://foo.bar/login.php?t=1&wid=${wid}">login</a> ...';
I think that this is only done with a regular expression , for this reason I wrote this function :
function makeLinks($str)
{
$str = preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '$1?wid=${wid}', $str);
return $str;
}
But this pattern having problems! for example :
http://google.com?foo=bar => http://google.com?wid=${wid}?foo=bar
Please help me.