Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save moriarty99779/76aa36574442d8e70995c8df77bec714 to your computer and use it in GitHub Desktop.
Save moriarty99779/76aa36574442d8e70995c8df77bec714 to your computer and use it in GitHub Desktop.
PHP Turn a URL inside of a string into a clickable link
function linkify_string ($stringwithurl) {
return "<p>" . preg_replace('!(http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?&_\-\=/]+!', "<a target='_blank' href=\"\\0\">\\0</a>", $stringwithurl) . "</p>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment