2017-04-21 33 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 –