Created
July 20, 2017 08:09
-
-
Save makgithub/2524d16628d1c0a8af697b1345edc84b to your computer and use it in GitHub Desktop.
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 | |
//Function definations | |
function MakeUrls($str) | |
{ | |
$find=array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si','`((?<!//)(www\.\S+[[:alnum:]]/?))`si'); | |
$replace=array('<a href="$1" target="_blank">$1</a>', '<a href="http://$1" target="_blank">$1</a>'); | |
return preg_replace($find,$replace,$str); | |
} | |
//Function testing | |
$str="aaa test www.cloudlibz.com https://stackoverflow.com www.writephponline.com/"; | |
$str=MakeUrls($str); | |
echo $str; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
convert the url to link in php text object