Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. /**
  2.  * Turns all urls into clickable links.
  3.  */
  4. function _auto_link_urls($text, $href_options = array(), $truncate = false, $truncate_len = 40, $pad = '...')
  5. {
  6.   $href_options = _tag_options($href_options);
  7.  
  8.   $callback_function = '
  9.    if (preg_match("/<a\s/i", $matches[1]))
  10.    {
  11.      return $matches[0];
  12.    }
  13.    ';
  14.  
  15.   if ($truncate)
  16.   {
  17.     $callback_function .= '
  18.      else if (strlen($matches[2].$matches[3]) > '.$truncate_len.')
  19.      {
  20.        return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.substr($matches[2].$matches[3], 0, '.$truncate_len.').\''.$pad.'</a>\'.$matches[4];
  21.      }
  22.      ';
  23.   }
  24.  
  25.   $callback_function .= '
  26.    else
  27.    {
  28.      return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.$matches[2].$matches[3].\'</a>\'.$matches[4];
  29.    }
  30.    ';
  31.  
  32.   return preg_replace_callback(
  33.     SF_AUTO_LINK_RE,
  34.     create_function('$matches', $callback_function),
  35.     $text
  36.     );
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement