From: Louis Jeckel Date: Thu, 27 Aug 2020 17:06:40 +0000 (+0200) Subject: Update GetPageTitleFromUrl.php X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b3044357dbf6f70ce694e90234541b62e7c56622;p=psq.git Update GetPageTitleFromUrl.php --- diff --git a/app/Invokables/GetPageTitleFromUrl.php b/app/Invokables/GetPageTitleFromUrl.php index d1e7ed5..51fbb87 100644 --- a/app/Invokables/GetPageTitleFromUrl.php +++ b/app/Invokables/GetPageTitleFromUrl.php @@ -6,9 +6,10 @@ namespace App\Invokables; class GetPageTitleFromUrl { - public function __invoke($url) + public function __invoke($url): string { + $unknown = "Titre inconnu"; $context = stream_context_create( [ "http" => [ @@ -21,8 +22,10 @@ class GetPageTitleFromUrl if($str !== ''){ $str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside preg_match("/<title>(.*)<\/title>/i",$str,$title); // ignore case - return $title[1]; + return $title[1] ?? $unknown; } + + return $unknown; } }