rendered paste bodyfunction getDocumentTitle($url) {
$pURL = parse_url($url);
if (empty($pURL['host'])) {
return $url;
}
if (empty($pURL['path'])) {
$pURL['path'] = '/';
}
if (empty($pURL['query'])) {
$document = $pURL['path'];
} else {
$document = $pURL['path'] . '?' . $pURL['query'];
}
$fp = fsockopen($pURL['host'], 80, $errno, $errstr, 30);
if (!$fp) {
return $url;
} else {
$out = "GET $document HTTP/1.1\r\n";
$out .= "Host: {$pURL['host']}\r\n";
$out .= "Connection: Close\r\n\r\n";
$received = '';
fwrite($fp, $out);
while (!feof($fp)) {
$received .= fgets($fp, 128);
}
fclose($fp);
}
if (!preg_match('~<title>(.*)</title>~isu', $received, $matches)) {
return $url;
}
return $matches[1];
}