dongyingdao8867 2014-10-30 13:06
浏览 323

从JSON解析视频名称和网址

I need help to parse the names and URLs of videos from some JSON data.

<?php

$json = file_get_contents('http://odnoklassniki.ru/dk?cmd=videoPlayerMetadata&mid=507252337');

$obj = json_decode($json);
foreach($obj->videos as $videos){
    $string = $videos->url;

$arr = explode('clientType=0',$string);
$string = implode('clientType=0", type:"mp4"},',$arr);
$arr = explode('http',$string);
$string = implode('{ file: "http',$arr);
echo $string;
}
?>

I need also the "name":

"name":"lowest"
"name":"low"
"name":"sd"
"name":"hd"

original url:

http://odnoklassniki.ru/dk?cmd=videoPlayerMetadata&mid=507252337

you can test it here:

http://codepad.viper-7.com/JDiU4h

  • 写回答

3条回答 默认 最新

  • donoworuq450547191 2014-10-30 13:21
    关注
    <?php
    
       $json = file_get_contents('http://odnoklassniki.ru/dk?cmd=videoPlayerMetadata&mid=507252337');
    
       $obj = json_decode($json);
       foreach($obj->videos as $video){
          echo $video->name .' :: '. $video->url;
          echo '<br>';
       }
    ?>
    

    $video variable is an stdClass object, this means you can retrieve another values by $video->value.

    评论

报告相同问题?