Return to Snippet

Revision: 28544
at July 9, 2010 09:56 by keevkilla


Initial Code
// Returns the text given as parameter, with contained URLs interpreted as HTML links

function link($text){
  return preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '<a href="$1">$1</a>', $text);
}

Initial URL


Initial Description
A source to help you interpreting URLs in plain text as a HTML link. It's an improvement of what was proposed here : http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/

Initial Title
Improvement of URL interpretation with regex

Initial Tags
regex, url, php

Initial Language
PHP