<?php
$content = file_get_contents('http://www.inc.com/patricia-fletcher/how-to-avoid-the-most-common-start-up-marketing-mistakes.html');
var_dump($content);
?>
爲什麼會返回?來自file_get_contents的奇怪結果
如果我更換http://google.com一切的URL似乎是罰款。
<?php
$content = file_get_contents('http://www.inc.com/patricia-fletcher/how-to-avoid-the-most-common-start-up-marketing-mistakes.html');
var_dump($content);
?>
爲什麼會返回?來自file_get_contents的奇怪結果
如果我更換http://google.com一切的URL似乎是罰款。
服務器正在返回內容gzip:ed。
您因而需要gunzip
它能夠讀取它。一種方法是使用Zlib功能:
$zd = gzopen('http://www.inc.com/patricia-fletcher/how-to-avoid-the-most-common-start-up-marketing-mistakes.html', "r");
$contents = gzread($zd, 100000);
gzclose($zd);
echo $contents;
輸出:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<title>How to Avoid the Most Common Start-Up Marketing Mistakes | Inc.com</title>
<meta name="description" content="Know when and where to invest and get the most from your marketing dollars" />
...
響應被gzip壓縮,使用gzdecode()。
$c = file_get_contents('http://www.inc.com/patricia-fletcher/how-to-avoid-the-most-common-start-up-marketing-mistakes.html');
echo gzdecode($c);
因爲這就是網站的回報。 (主要發生在不接受Accept-Encoding的網站上。) – mario