Turn Plain Text URLs into Active Links using PHP

I was putting together a bit of code to pull in a Twitter feed, similar to what you see in the footer of bavotasan.com. I got everything working properly but the only problem was all of the URLs were just plain text instead of active links. I figured out a way to automatically turn the URLs into active links using a small piece of PHP.
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","\0", $text);
The code finds all instances of http:// and converts the string into an active link by surrounding it with an anchor tag.
Search

Popular Posts

Small Biz Website Tips Newsletter

Stay up to date with the latest marketing, sales, and service tips and news.

Small Biz Website Tips Newsletter

Stay up to date with the latest marketing, sales, and service tips and news.