Last active
January 3, 2016 20:39
-
-
Save karmiphuc/8516566 to your computer and use it in GitHub Desktop.
URL Parsing from text
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
<? | |
function parseUrl($s) { | |
$__ = preg_replace('/([A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+)/i', '<a href="$1" target="_blank">$1</a>', $s); | |
return preg_replace('/(^| )([^\/])((www|[^\/\. ]+)\.[A-Za-z]+(\b|$|))/i', '$1<a href="http://$2$3" target="_blank">$2$3</a>', $__); | |
}; | |
$s = 'Tinhte.vn asdasd google.com asdjaskdjajks www.abc.com xxx Google http://google.com.vm/search/asdajs.html'; | |
var_dump(parseUrl($s)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment