Created
April 29, 2011 14:38
-
-
Save jeremyboggs/948395 to your computer and use it in GitHub Desktop.
Function to convert any URLs in a given string to links.
This file contains hidden or 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 | |
/** | |
* Converts any URLs in a given string to links. | |
* | |
* @param string $str The string to be searched for URLs to convert to links. | |
* @return string | |
**/ | |
function url_to_link($str) | |
{ | |
$pattern = "((https?://)+[\w\d:#@%!/;$()~_?\+-=\\\.&]*)"; | |
$str = preg_replace($pattern, '<a href="\0">\0</a>', $str); | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment