如何使用file_get_contents在php中的远程Web服务器上获取gzip格式的页面? [英] How do I use file_get_contents to get a gzip'ed page on a remote web server in php?

查看:80
本文介绍了如何使用file_get_contents在php中的远程Web服务器上获取gzip格式的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过php 5.2.9中的file_get_contents接收页面的gzip压缩版本

I'm trying to receive a gzip'ed version of a page through file_get_contents in php 5.2.9

我可以使用fopen使用以下代码来做到这一点:

I was able to do it using fopen with the following code:

    $opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Accept-Encoding: gzip\r\n"
  )
);

$context = stream_context_create($opts);
ob_start();
$fp = fopen('http://example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
$content = ob_get_contents();
ob_end_clean();

那行得通,但是我希望有一种方法可以使用file_get_contents来代替.

That works, but I was hoping there was a way I could do it using file_get_contents instead.

谢谢.

推荐答案

您尝试过吗?

$content = file_get_contents('http://example.com',false,$context);

这篇关于如何使用file_get_contents在php中的远程Web服务器上获取gzip格式的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆