Posted By

troynt on 02/28/09


Tagged

regex


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

luman


Linkify - Convert Text to Links


 / Published in: PHP
 

  1. function linkify($text)
  2. {
  3. $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
  4. '<a href="\\1">\\1</a>', $text);
  5.  
  6. $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
  7. '\\1<a href="http://\\2">\\2</a>', $text);
  8.  
  9. $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
  10. '<a href="mailto:\\1">\\1</a>', $text);
  11. return $text;
  12. }

Report this snippet  

You need to login to post a comment.