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:
parent
3ba5289684
commit
690f53c8f5
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user