Same name and namespace in other branches
  1. 5.x modules/filter/filter.module \_filter_url()
  2. 7.x modules/filter/filter.module \_filter_url()
  3. 8.9.x core/modules/filter/filter.module \_filter_url()
  4. 9 core/modules/filter/filter.module \_filter_url()

URL filter. Automatically converts text web addresses (URLs, e-mail addresses, FTP links, etc.) into hyperlinks.

Related topics

File

modules/filter/filter.module, line 751
Framework for handling filtering of content.

Code

function _filter_url($text, $format) {

  // Pass length to regexp callback
  _filter_url_trim(NULL, variable_get('filter_url_length_' . $format, 72));
  $text = ' ' . $text . ' ';

  // Match absolute URLs.
  $text = preg_replace_callback("`(<p>|<li>|<br\\s*/?>|[ \n\r\t\\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?!]*?)(?=(</p>|</li>|<br\\s*/?>|[ \n\r\t\\)]))`i", '_filter_url_parse_full_links', $text);

  // Match e-mail addresses.
  $text = preg_replace("`(<p>|<li>|<br\\s*/?>|[ \n\r\t\\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\\.[A-Za-z]{2,4})([.,?!]*?)(?=(</p>|</li>|<br\\s*/?>|[ \n\r\t\\)]))`i", '\\1<a href="mailto:\\2">\\2</a>\\3', $text);

  // Match www domains/addresses.
  $text = preg_replace_callback("`(<p>|<li>|[ \n\r\t\\(])(www\\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\\&=/;-])([.,?!]*?)(?=(</p>|</li>|<br\\s*/?>|[ \n\r\t\\)]))`i", '_filter_url_parse_partial_links', $text);
  $text = substr($text, 1, -1);
  return $text;
}