Skip to content

Instantly share code, notes, and snippets.

@anunay
Created June 12, 2013 23:11
Show Gist options
  • Save anunay/5769934 to your computer and use it in GitHub Desktop.
Save anunay/5769934 to your computer and use it in GitHub Desktop.
PHP: Make Clickable
<?php
/**
* Supports normal, ftp, file and email URL’s as well as subdomains.
* Also it doesn’t mess with HTML a tags that already exist in the string.
*
* @param String $text Contens that needs to be parsed through
* @return String String
*
*/
function make_clickable($text){
return preg_replace('@(?<![.*">])\b(?:(?:https?|ftp|file)://|[a-z]\.)[-A-Z0-9+&#/%=~_|$?!:,.]*[A-Z0-9+&#/%=~_|$]@i', '<a href="\0">\0</a>', $text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment