Created
June 12, 2013 23:11
-
-
Save anunay/5769934 to your computer and use it in GitHub Desktop.
PHP: Make Clickable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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