2015-11-11 39 views
0

我使用file_get_contents函數PHP從網站獲取數據,它運行良好。但對於這個網址:file_get_contents得到錯誤的內容

http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fwww.google.com%2F

它沒有得到實際的內容目前。

<?php 
    echo file_get_contents('http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fwww.goolge.com%2F'); 
?> 
+0

最有可能的某種重定向,因爲http://www.youtube.com將被重定向到https。也許嘗試直接訪問https版本。 –

回答

0

是的它確實返回相同的,但你不能看到它,因爲它是很多的HTML和Javascript。

下面是一個例子來讀取JSON內容:

header("Content-Type: text/plain"); 
$json = file_get_contents('http://benalman.com/code/projects/php-simple-proxy/ba-simple-proxy.php?url=http%3A%2F%2Fwww.youtube.com%2F'); 
print_r(json_decode($json));