Esempio n. 1
0
 /**
  * Turns all urls into clickable links.  
  * 
  * Example:
  *  <?=$text_helper->auto_link_urls($post->body, array('all', 'target' => '_blank'));?>
  */
 function auto_link_urls($text, $href_options = array())
 {
     $extra_options = TagHelper::_tag_options($href_options);
     $links = TextHelper::get_urls_from_text($text);
     $linked_urls = TextHelper::get_linked_urls_from_text($text);
     $urls_to_replace = array_diff(array_keys($links), $linked_urls);
     $find = array();
     $replace = array();
     foreach ($urls_to_replace as $url_to_replace) {
         $find[] = '@' . preg_quote($url_to_replace) . '@';
         $replace[] = '<a href="' . $links[$url_to_replace] . '"' . $extra_options . '>' . $url_to_replace . '</a>';
     }
     return preg_replace($find, $replace, $text);
 }