【问题标题】:file_get_contents but no loadfile_get_contents 但没有负载
【发布时间】:2017-04-21 12:42:38
【问题描述】:

我创建了一个 php 代码,通过使用 file_get_contents 从该页面的标签“hlsUrl”中获取第一个 m3u8 链接,但它不起作用,请提供任何帮助

我的代码是

> <?php
> 
> $link =
> "https://stream.live/-/streams/users/kawkaw?includeTrending=true" ;
> 
>    $actualLink = file_get_contents($link);
>      echo $actualLink->find("hlsUrl");
> 
> ?>

【问题讨论】:

  • $actualLink是字符串,字符串没有函数find。
  • file_get_contents 会返回字符串,所以没有find 方法。先解析一下
  • 另外,为了将来参考,说 “但它不起作用” 对任何人都没有帮助。向我们显示错误消息。
  • 不工作我的意思是在浏览器显示页面上不会像网站不工作一样加载:)

标签: php file-get-contents


【解决方案1】:

您的file_get_contents 将返回字符串 JSON。所以需要先解析一下。

$link = "https://stream.live/-/streams/users/kawkaw?includeTrending=true";
$actualLink = file_get_contents($link);
$actualJson = json_decode($actualLink);
echo $actualJson->trendingStreams[0]->hlsUrl;

【讨论】:

  • 感谢现在显示大量数据的页面,但我只需要显示第一个标记为“hlsUrl”的 m3u8 链接,请帮助!
  • @stephanenelson 在您发表评论之前,我实际上已经更新了我的答案。请学习如何解析 JSON 并访问它的元素
  • 拜托我需要 sme 帮助,你能帮我只解析用户名 kawkaw 的 hlsUrl
猜你喜欢
  • 1970-01-01
  • 2012-05-03
  • 2011-02-22
  • 2013-09-10
  • 1970-01-01
  • 1970-01-01
  • 2015-07-23
  • 1970-01-01
  • 2018-01-27
相关资源
最近更新 更多