2013-10-30 51 views
0

我創建了一種Facebook的鏈接分享,這得到所有的meta標籤與稱爲元數據獲得在PHP

代碼parcitular類元數據類的meta標籤很簡單:

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"; 
} 

現在,它返回每個元標籤,但如果我選擇一個特定的標籤,我可以做到這一點?

例如,我只想得到標題,描述和圖像。

我試過$ 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 

Link類:MetaData

+0

不知您對腳本的輸出? – TiMESPLiNTER

+0

講述'metadata.class.php',它是如何工作的以及你在哪裏找到它,任何鏈接,你的關聯數組是如何看起來的? –

+0

對,謝謝你的提示:D –

回答

0

使用代碼:

$metaData['description'] 
+0

這並沒有提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 - [來自評論](/ review/low-quality-posts/16522212) – Blackbam

+0

爲什麼不呢?最近幾天我在我的項目中使用了圖書館metadata.class.php。變量$ metaData是一個關聯數組,其所有元標記都是關鍵字,可以在發佈的原始輸出中讀取。使用$ value ['description'](有問題)是沒有意義的。問題是如何分別提取項目,解決方案是用desidered鍵調用關聯數組$ metaData,例如$ metaData ['description']。在你看來,爲什麼我沒有提供答案,而是要求? –