2017-04-21 29 views
0

我创建一个PHP代码使用的file_get_contents得到从这个网页标签“hlsUrl”第一M3U8链接,但它不工作,任何帮助,请的file_get_contents但空载

我的代码是

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

'$ actualLink'是一个字符串,而一个字符串没有函数'find'。 – Jerodev

+3

'file_get_contents'将返回字符串,所以没有'find'方法。首先解析它 – Justinas

+2

此外,为了将来的参考,说*“但它不工作”*对任何人都没有帮助。向我们显示错误消息。 –

回答

0

您的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; 
+0

现在感谢页面显示了大量的数据,但我只需要显示“hlsUrl”第一个m3u8链接,请任何帮助! –

+1

@stephanenelson在您的评论之前,我已经实际更新了我的答案。请学习如何解析JSON并访问它的元素 – Justinas

+0

youpoiiiiiiiiii now works 1000000 thanks <3 –

相关问题