【问题标题】:get meta tags with MetaData class in php在 php 中使用 MetaData 类获取元标记
【发布时间】:2013-11-10 06:57:14
【问题描述】:

我正在创建一种 facebook 链接共享,它使用名为 MetaData 的特殊类获取所有元标记

代码很简单:

require_once('metadata.class.php');

$metaData = MetaData::fetch('http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html');

// returns an associative array
var_dump($metaData->tags());

foreach ($metaData as $key => $value) {
    echo "$key => $value";
}

现在,它返回每个元标记,但如果我要选择一个特定的标记,我该怎么做?

例如,我只想获取标题、描述和 og 图片。

我尝试使用 $value['description'] 但它返回空调用,有什么想法吗?

通常会这样:

array(26) { ["title"]=> string(60) "Ken Robinson: How schools kill creativity | Video on TED.com" ["description"]=> string(149) "Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity." ["keywords"]=> string(63) "TED,Talks,children,creativity,culture,dance,education,parenting" ["medium"]=> string(5) "video" ["apple-itunes-app"]=> string(101) "app-id=376183339,app-argument=http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["robots"]=> string(13) "index, follow" ["og:title"]=> string(60) "Ken Robinson: How schools kill creativity | Video on TED.com" ["og:description"]=> string(149) "Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity." ["og:image"]=> string(48) "http://images.ted.com/images/ted/221_389x292.jpg" ["og:url"]=> string(71) "http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["og:type"]=> string(11) "video.other" ["video:tag"]=> array(8) { [0]=> string(3) "TED" [1]=> string(5) "Talks" [2]=> string(8) "children" [3]=> string(10) "creativity" [4]=> string(7) "culture" [5]=> string(5) "dance" [6]=> string(9) "education" [7]=> string(9) "parenting" } ["video:duration"]=> string(4) "1164" ["video:release_date"]=> string(10) "1151367060" ["twitter:card"]=> string(7) "summary" ["twitter:site"]=> string(9) "@tedtalks" ["twitter:title"]=> string(60) "Ken Robinson: How schools kill creativity | Video on TED.com" ["twitter:description"]=> string(149) "Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity." ["twitter:image:src"]=> string(48) "http://images.ted.com/images/ted/221_389x292.jpg" ["twitter:app:name:iphone"]=> string(9) "TED Talks" ["twitter:app:id:iphone"]=> string(9) "376183339" ["twitter:app:url:iphone"]=> string(71) "http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["twitter:app:name:ipad"]=> string(9) "TED Talks" ["twitter:app:id:ipad"]=> string(9) "376183339" ["twitter:app:url:ipad"]=> string(71) "http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.html" ["fb:app_id"]=> string(15) "201021956610141" } title => Ken Robinson: How schools kill creativity | Video on TED.comdescription => Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity.keywords => TED,Talks,children,creativity,culture,dance,education,parentingmedium => videoapple-itunes-app => app-id=376183339,app-argument=http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmlrobots => index, followog:title => Ken Robinson: How schools kill creativity | Video on TED.comog:description => Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity.og:image => http://images.ted.com/images/ted/221_389x292.jpgog:url => http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmlog:type => video.othervideo:tag => Arrayvideo:duration => 1164video:release_date => 1151367060twitter:card => summarytwitter:site => @tedtalkstwitter:title => Ken Robinson: How schools kill creativity | Video on TED.comtwitter:description => Sir Ken Robinson makes an entertaining and profoundly moving case for creating an education system that nurtures (rather than undermines) creativity.twitter:image:src => http://images.ted.com/images/ted/221_389x292.jpgtwitter:app:name:iphone => TED Talkstwitter:app:id:iphone => 376183339twitter:app:url:iphone => http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmltwitter:app:name:ipad => TED Talkstwitter:app:id:ipad => 376183339twitter:app:url:ipad => http://www.ted.com/talks/ken_robinson_says_schools_kill_creativity.htmlfb:app_id => 201021956610141f

链接类:MetaData

【问题讨论】:

  • 你的脚本的输出是什么?
  • 说说metadata.class.php,它是如何工作的,你在哪里找到的,任何链接,你的关联数组是什么样子的?
  • 好的,谢谢你的提示:D

标签: php facebook metadata sharing


【解决方案1】:

使用代码:

$metaData['description']

【讨论】:

  • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
  • 为什么不呢?最近几天,我在我的项目中使用了库 metadata.class.php。变量 $metaData 是一个关联数组,所有元标记作为键,可以在发布的原始输出中读取。使用 $value['description'] (有问题)没有意义。问题是如何单独提取项目,解决方案是使用所需的键调用关联数组 $metaData,例如 $metaData['description']。在您看来,为什么我没有提供答案而是提出请求?
猜你喜欢
  • 2012-08-14
  • 1970-01-01
  • 2012-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-17
相关资源
最近更新 更多