Using CURL instead of file_get_contents to grab GZIP compressed web pages

time:17-06-28 forum:PHP tools and code
  http://www.nowamagic.net/librarys/veda/detail/1770

coding problem is good. What we are talking about here is how to grab the Gzip page. How to judge? The Content-Encoding: gzip in the header is GZIP compressed. If you look at it with FireBug, you know that the page is gzip. Next is to use firebug to check the header information of my blog, and Gzip is open.

[code]Accept text/html, application/xhtml XML, application/xml; q=0.9, * / *; q=0.8
Accept-Encoding gzip. 1335411401.1537; __utmz=225240837.1326850415.887.3.utmcsr=google|utmccn= (organic) |utmcmd=organic|utmctr= will not be so simple as site:www.nowamagic.net; PHPSESSID=888mj4425p8s0m7s0frre3ovc7; __utmc=225240837; __utmb= 225240837.1.10.1335411401
Host www.nowamagic.net
User-Agent Mozi Lla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0[/code]

below to introduce some solutions:

1. uses a zlib library with its own zlib library
if the server has installed a library, the following code can easily be used to solve the problem of chaos.

[code]$data = file_get_contents (.Quot; compress.zlib://.quot;.$url); [/code]

2. using CURL instead of file_get_contents if ($gzip) curl_setopt ($curl, CURLOPT_ENCODING,.Quot; gzip.quot;); / / / / key here
$content = curl_exec.
  • 2

prev:Use.Htaccess to prevent images from bein... next:PHP curl function simulated crawler (ope...
post comment
Notice



approved   The first generation of migrant work...   Children go to school, Ji'nan addres...   Ji'nan: 27 year old girl loves croch...   The "one school one product" sports ...   These "90" in the mountains, the vil...
rand   PHP removes the tail space and decim...   Simple text filtering function of PH...   [ASP] [PHP] set up as a desktop shor...   PHP Chinese character conversion fun...   How to generate a histogram dynamica...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com