Created
April 21, 2015 18:49
-
-
Save juniorb2ss/2f12534897ee9684fa8e to your computer and use it in GitHub Desktop.
Find URL in String
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 | |
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; | |
$text = "Visite: http://google.com e pesquise antes de perguntar."; | |
if(preg_match($reg_exUrl, $text, $url)) { | |
echo preg_replace($reg_exUrl, "<a href=$url[0]>$url[0]</a>", $text); | |
} else { | |
echo $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment