PHPでOGPを取得する

function getOGP($file,$ogps = ['title','description','image']){
    $html = @file_get_contents($file);
    if(!$html){ return false; }
    $html = mb_convert_encoding($html, 'HTML-ENTITIES','ASCII,JIS,UTF-8,EUC-JP,SJIS');
    $dom = new DOMDocument();
    $err = @$dom->loadHTML($html);
    if(!$err){ return false; }
    $return = (object)[];
    $metas = $dom->getElementsByTagName('meta');
    foreach($metas as $m){
        $prop = str_replace('og:','',$m->getAttribute('property'));
        if(in_array($prop,$ogps)){
            $return->$prop = $m->getAttribute('content');
        }
    }   
    return $return;
}
$ogp = getOGP('https://www.google.co.jp/');
カテゴリーPHP