【问题标题】:How to get Dailymotion title [closed]如何获得 Dailymotion 标题 [关闭]
【发布时间】:2012-01-29 14:32:43
【问题描述】:

您好,我正在尝试从 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'];

我找不到问题出在哪里。谢谢

【问题讨论】:

    标签: php video title


    【解决方案1】:

    问题是您正在返回 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'];
    

    【讨论】:

    • Teşekkürler Ahmet.thx 寻求帮助 :)
    【解决方案2】:

    你得到一个 json 响应,所以使用json_decode 函数来获取一个 JSON 编码的字符串并将其转换为一个 PHP 变量。

    喜欢:

    $array = json_decode($hash, true);
    
    echo $array['title'];
    

    $array = json_decode($hash);
    
    echo $array->title;
    

    【讨论】:

    • 不。他必须对 $hash 进行 json_decode。因为返回值是编码的:-)
    • 别忘了第二个参数 json_decode($hash,true);否则它将返回一个对象
    • 或 $array->title 而不是 $array['title'].. 我编辑了它,但仍在等待审核:)
    猜你喜欢
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 2018-06-30
    • 2013-04-04
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多