Home  >  Q&A  >  body text

怎么通过php取以下接口中的指定内容呢?

这是我随便抓的一个接口地址:http://interface.yy.com/hls/get/0/54880976/54880976?appid=0&excid=1200&type=m3u8&callback=jsonp2

输出后文本如下

jsonp2({"code":0,"hls":"http://hls.yy.com/newlive/54880976_54880976.m3u8?org=yyweb&appid=0&uuid=b09929c952f34f059f1c637a7de4f3be&t=1482754694&tk=08dbec696bb3a17c03a4472bf9ae5993&uid=0&ex_audio=0&ex_coderate=1200&ex_spkuid=0"})

我想取里面这段连接地址:

http://hls.yy.com/newlive/54880976_54880976.m3u8?org=yyweb&appid=0&uuid=b09929c952f34f059f1c637a7de4f3be&t=1482754694&tk=08dbec696bb3a17c03a4472bf9ae5993&uid=0&ex_audio=0&ex_coderate=1200&ex_spkuid=0

我使用组数获取不知道哪里错了?麻烦帮忙看看修改一下谢谢!

$url="http://interface.yy.com/hls/get/0/54880976/54880976?appid=0&excid=1200&type=m3u8&callback=jsonp2";

$json=json_decode($url,true);

$str=$json["code"]["hls"];

echo $str;exit;






phpcn_u290phpcn_u2902828 days ago1544

reply all(4)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:49:03

    How to get the specified content in the following interface through php? -PHP Chinese website Q&A-How to get the specified content in the following interface through php? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • PHP中文网

    PHP中文网2016-12-26 22:36:59

    截图:QQ截图20161226223859.jpg

    reply
    1
  • PHP中文网

    PHP中文网2016-12-26 22:34:40

    <?php

    $url="http://interface.yy.com/hls/get/0/54880976/54880976?appid=0&excid=1200&type=m3u8&callback=jsonp2";

    $data=str_replace('})','}',str_replace('jsonp2({','{',file_get_contents($url)));

    $json=json_decode($data,true);

    $str=$json["hls"];

    echo $str;

    exit;


    reply
    1
  • PHP中文网

    PHP中文网2016-12-26 22:28:40

    那是jsonp接口,建议使用js接收,可以在js中定义个jsonp2函数,json数据就是参数。


    reply
    1
  • phpcn_u290

    谢谢!学习了!

    phpcn_u290 · 2016-12-27 13:10:43
  • Cancelreply