function _filter_url in Drupal 5
Same name and namespace in other branches
- 8 core/modules/filter/filter.module \_filter_url()
- 6 modules/filter/filter.module \_filter_url()
- 7 modules/filter/filter.module \_filter_url()
- 9 core/modules/filter/filter.module \_filter_url()
URL filter. Automatically converts text web addresses (URLs, e-mail addresses, ftp links, etc.) into hyperlinks.
1 call to _filter_url()
- filter_filter in modules/
filter/ filter.module - Implementation of hook_filter(). Contains a basic set of essential filters.
File
- modules/
filter/ filter.module, line 1128 - 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;
}