I’m attempting to convert the URLs in a string into clickable hyperlinks. I wrote a little function but it doesn’t seem to be doing the trick:
function parseHyperlinks($string) {
// Add <a> tags around all hyperlinks in $string
return ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\\"\\\\0\\" target=\\"_blank\\">\\\\0</a>", $string);
}
Now before you tell me that ereg_replace is deprecated - I know it is. This is an old function I wrote some time ago and just archived it. I’m using PHP 5.2.9 which technically means it should work. I’m happy to accept a preg_replace function but not sure what the differences are.
When I use this function, no errors are returned but no results are returned either. I’m sure there’s a technical term for this but the PHP stops processing and just spits out what it already came up with. No additional HTML is sent to the browser after this bit of code - it’s blank.
Any help is appreciated. I’m not against abandoning this function completely in favor of a different solution you recommend.