function url_fetch_title in URL field 8
Same name and namespace in other branches
- 7 url.module \url_fetch_title()
Return the HTML title from an URL.
Parameters
string $url: An URL to request with drupal_http_request().
Return value
string The HTML title of the URL if found.
1 call to url_fetch_title()
- url_field_presave in ./
url.module - Implements hook_field_presave().
File
- ./
url.module, line 332 - Provides a URL field type that stores external links with optional titles.
Code
function url_fetch_title($url) {
$request = drupal_http_request($url);
if (empty($request->error) && $request->code == 200 && !empty($request->data)) {
if (preg_match('!<title>(.*?)</title>!i', $request->data, $matches)) {
// Title tags should be encoded, but we want the raw value.
return decode_entities($matches[1]);
}
}
}