1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-02-23 02:32:27 +01:00

Return host of URL if title cannot be obtained in title helper

This commit is contained in:
Kovah 2018-08-27 12:59:56 +02:00
parent 3ba5289684
commit 690f53c8f5
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B

View File

@ -12,20 +12,26 @@ class LinkAce
/**
* Get the title of an HTML page b
* @param string $url
* @return null|string|string[]
* @return string|string[]
*/
public static function getTitleFromURL(string $url)
{
$fp = file_get_contents($url);
$fail_return = parse_url($url, PHP_URL_HOST);
try {
$fp = file_get_contents($url);
} catch (\Exception $e) {
return $fail_return;
}
if (!$fp) {
return null;
return $fail_return;
}
$res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
if (!$res) {
return null;
return $fail_return;
}
// Clean up title: remove EOL's and excessive whitespace.