Answers for "php get site metat tags"

PHP
0

php get site metat tags

function getSiteOG( $url, $specificTags=0 ){
  $doc = new DOMDocument();
  @$doc->loadHTML(file_get_contents($url));
  $res['title'] = $doc->getElementsByTagName('title')->item(0)->nodeValue;

  foreach ($doc->getElementsByTagName('meta') as $m){
      $tag = $m->getAttribute('name') ?: $m->getAttribute('property');
      if(in_array($tag,['description','keywords']) || strpos($tag,'og:')===0) $res[str_replace('og:','',$tag)] = $m->getAttribute('content');
  }
  return $specificTags? array_intersect_key( $res, array_flip($specificTags) ) : $res;
}
Posted by: Guest on September-26-2020

Browse Popular Code Answers by Language