Created
November 20, 2019 15:17
-
-
Save mesbahulalam/39a363a00d0e9b901846b01de8bfb571 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 | |
// The Regular Expression filter | |
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; | |
// The Text you want to filter for urls | |
$text = "The text you want to filter goes here. http://google.com"; | |
// Check if there is a url in the text | |
if(preg_match($reg_exUrl, $text, $url)) { | |
// make the urls hyper links | |
echo preg_replace($reg_exUrl, "<a href="{$url[0]}">{$url[0]}</a> ", $text); | |
} else { | |
// if no urls in the text just return the text | |
echo $text; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment