使用Open Graph Protocol提取og:图像源

时间:2012-10-29 22:44:35

标签: php regex github opengraph

使用https://github.com/scottmac/opengraph

如何访问各个数组元素,例如[image]

$graph = OpenGraph::fetch('http://www.avessotv.com.br/bastidores-pantene-institute-experience-pg.html');
print_r($graph);

将返回

OpenGraph Object    
(
    [_values:OpenGraph:private] => Array
        (
            [type] => article
            [video] => http://www.avessotv.com.br/player/flowplayer/flowplayer-3.2.7.swf..
            [image] => /wp-content/thumbnails/9025.jpg
            [site_name] => Programa Avesso - Bastidores
            [title] => Bastidores “Pantene Institute Experience†P&G
            [url] => http://www.avessotv.com.br/bastidores-pantene-institute-experience-pg.html
            [description] => Confira os bastidores do Pantene Institute Experience, da Procter & Gamble. www.pantene.com.br Mais imagens:
        )

    [_position:OpenGraph:private] => 0
)

2 个答案:

答案 0 :(得分:2)

简单到$graph->type$graph->video等。

来自记录的来源:

  /**
   * Helper method to access attributes directly
   * Example:
   * $graph->title
   *
   * @param $key    Key to fetch from the lookup
   */
  public function __get($key){

答案 1 :(得分:2)

这是PHP magic

使用$image_url = $graph->image;