I'm trying to use ereg_replace to reformat user-entered URLs into hyperlinks (i.e. adding the necessary <a href="stuff"></a>) when data is read back by php.
I found something on a regexp website that seems pretty complete, but it doesn't work as supplied. I keep getting "Warning: REG_ERANGE" when I run it as supplied, which is:
$vdom = "[:alnum:]"; // Valid domain chars
$vurl = $vdom."_~-"; // Valid subdomain and path chars
$vura = $vurl."A-?a-y!#$%&*+,;=@."; // Valid additional parameters (after '?') chars;
// insert other local characters if needed
$protocol = "[[:alpha:]]{3,10}://"; // Protocol exp
$server = "([$vurl]+[.])+[$vdom]+"; // Server name exp
$path = "(([$vurl]+([.][$vurl]+)*/)|([.]{1,2}/))*"; // Document path exp (/.../)
$name = "[$vurl]+([.][$vurl]+)*"; // Document name exp
$params = "[?#%][$vura]*"; // Additional parameters (for GET)
ereg_replace("$protocol$server(/$path($name)?)?($params)?", "<a href=\"\\0\">\\0</a>", $myrow['eventinfo'])
But if I change the "$params" line to
$params = "[?#%][$vurl]*";)
it works fine, except if there are multiple "%" signs in the URL, in which case it drops out at the second instance. The problem is clearly in the $vura definition, but what's wrong with it is beyond my limited understanding.
Any wizards out there have a clue on this one? If I can make it work it'll be sweeeeet!