我有一个名为$graph
的变量,它携带从URL中抓取的OpenGraph数据。当我print_r
变量时,这就是它的样子:
Array (
[OpenGraph_values] => Array (
[url] => http://www.theguardian.com/sport/blog/2017/jun/05/lebron-james-cleveland-cavaliers-nba-finals
[description] => The Cleveland star’s greatness created an arms race in basketball, and it has reached its apotheosis in the Golden State Warriors
[image] => https://i.guim.co.uk/img/media/3746052fc5b7f0a1ffb9ee2d5cd79585c31149a8/562_880_4049_2429/master/4049.jpg?w=1200&h=630&q=55&auto=format&usm=12&fit=crop&crop=faces%2Centropy&bm=normal&ba=bottom%2Cleft&blend64=aHR0cHM6Ly91cGxvYWRzLmd1aW0uY28udWsvMjAxNi8wNS8yNS9vdmVybGF5LWxvZ28tMTIwMC05MF9vcHQucG5n&s=71512608e33d4fda4fcf6ca52ccbd2bf
[type] => article
[title] => LeBron James created the modern NBA superteam. Now it will destroy him
[site_name] => the Guardian
)
[OpenGraph_position] => 0
)
我不能为我的生活弄清楚如何访问那里的数据。我试过了$graph['image']
和$graph['OpenGraph_values']['image']
,但没有运气。两者都是空的。我必须要有一些非常简单的东西,但我对PHP很陌生,所以我甚至不知道如何搜索我的问题。
编辑:一些其他信息:
我是通过这样做来创建变量的:
$graph = (array)OpenGraph::fetch( $permalink );
其中$permalink
是带有URL的字符串。
使用此工具获取OpenGraph数据:https://github.com/scottmac/opengraph
如果有任何其他特别有用的,请告诉我。这是在WordPress网站上运行的,如果它完全相关的话。