How to Find a Url in a String and Wrap a Link Around it

Occasionally you have a string and you need to find the urls in it and convert them into fully functioning links. Do do this you need to useĀ  this script:

$string = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $string);

I have just updated one of my scripts with this line: Twitter feed using php and add link to any urls found

Tags: , , ,

About Keiron

Web Developer based in the UK. Click here if you want to work with me