Skip to content

Instantly share code, notes, and snippets.

@juniorb2ss
Created April 21, 2015 18:49
Show Gist options
  • Save juniorb2ss/2f12534897ee9684fa8e to your computer and use it in GitHub Desktop.
Save juniorb2ss/2f12534897ee9684fa8e to your computer and use it in GitHub Desktop.
Find URL in String
<?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