2012-01-29 52 views
-1

嗨,我想從dailymotion視頻獲取視頻標題。如何獲得Dailymotion標題

$imgid = $video_cek["embed"]; //this is dailymotion id (ex. xint71) 
$hash = unserialize(file_get_contents("http://www.dailymotion.com/services/oembed? 
format=json&url=http://www.dailymotion.com/embed/video/$imgid")); 
$video_cek['baslik']=$hash[0]['title']; 

我找不到哪裏是problem.Thanks

回答

-1

塞拉姆Gürsel,問題是你正在返回JSON格式,而試圖反序列化的是,這應該工作:

$imgid = $video_cek["embed"]; 
$hash = json_decode(file_get_contents("http://www.dailymotion.com/services/oembed?format=json&url=http://www.dailymotion.com/embed/video/$imgid"), true); 
$video_cek['baslik']= $hash['title']; 

我希望幫助:-)

+0

TeşekkürlerAhmet.thx for help :) – 2012-01-29 14:55:46

0

你得到一個JSON響應,所以使用json_decode函數來獲取一個JSON編碼字符串,並將其轉換成一個PHP變量。

,如:

$array = json_decode($hash, true); 

echo $array['title']; 

$array = json_decode($hash); 

echo $array->title; 
+0

不。他必須對$ hash進行json_decode。因爲返回值被編碼:-) – ahmet2106 2012-01-29 14:38:26

+0

是的,我立即修復它 – 2012-01-29 14:41:47

+0

不要忘記第二個參數json_decode($ hash,true);否則它會返回一個對象 – 2012-01-29 14:52:54