Created
June 7, 2014 08:21
-
-
Save esedic/4f59cd4f8988cd9bca9f to your computer and use it in GitHub Desktop.
Convert URLs within String into hyperlinks
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 | |
// This function converts URLs and e-mail addresses within a string into clickable hyperlinks. | |
function makeClickableLinks($text) { | |
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', | |
'<a href="\1">\1</a>', $text); | |
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)', | |
'\1<a href="http://\2">\2</a>', $text); | |
$text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})', | |
'<a href="mailto:\1">\1</a>', $text); | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment