Convert text URLs or Hyperlinks to clickable links

Here's a PHP code that can parse text URLs or Hyperlinks into a clickable link. This is useful when displaying text contents with inline links written along.

Some of the URLs this script can handle:

 * @param String $s
 * @return String
public static function markupUrls($s) {
  return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@''<a href="$1" target="_blank">$1</a>'$s);

Related posts:

Bookmark and Share


magento developer said...

I really loved read this blog. It has lot of information’s to the public. Thanks for sharing this information in internet

Dwndr said...

can I use this for Blogspot as well?

bassgrinder said...

Not sure if you could use that in Blogspot. Perhaps look for a Javascript counterpart of this. They're more welcome inside Blogspot themes.

Post a Comment

Hi there! Please leave your message here. Also, I may not be able to respond to your query right away. So please bear with me. Thanks. :)