在 php 中使用元数据类获取元标记


get meta tags with MetaData class in php

我正在创建一种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["描述"],但它返回空调用,有什么想法吗?

它通常得到这个:

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['description']