Skip to content

Instantly share code, notes, and snippets.

@esedic
Created June 7, 2014 08:21
Show Gist options
  • Save esedic/4f59cd4f8988cd9bca9f to your computer and use it in GitHub Desktop.
Save esedic/4f59cd4f8988cd9bca9f to your computer and use it in GitHub Desktop.
Convert URLs within String into hyperlinks
<?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