2012-01-29 79 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