Advertisement
markuszeller

url_to_html

May 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. function urltohtml($text)
  2. {
  3.     return preg_replace_callback('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)/', 'callback_linker', $text);
  4. }
  5.  
  6. function callback_linker($text)
  7. {
  8.     $lastchar = substr($text[0], -1, 1);
  9.     if(preg_match('/[^a-zA-Z0-9]/', $lastchar))
  10.     {
  11.         $href = substr($text[0], 0, -1);
  12.         $append = $lastchar;
  13.     }
  14.     else
  15.     {
  16.         $href = $text[0];
  17.         $append = '';
  18.     }
  19.     return "<a href=\"$href\">$href</a>$append";
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement