Posted By

jspicher on 10/09/09


Tagged

php text functions makeclickable


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

silentbob84


make_clickable($text)


 / Published in: PHP
 

Used to convert URLs in a string into links

  1. function make_clickable($text){
  2. $ret = " " . $text;
  3. $ret = preg_replace("#([\n ])([a-z]+?)://([^,\t \n\r]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $ret);
  4. $ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $ret);
  5. $ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
  6. $ret = substr($ret, 1);
  7. return($ret);}

Report this snippet  

You need to login to post a comment.