3

I'm trying to print an external site's HTML using curl, but when I go to print the html I just get a bunch of bad characters:

D\ÓLþ¢GΖ´ï!ñ{HÑ,Jþ»H¹§L+÷53j?‰²î¡<‘*tÜe÷uÖbìê~Æô¬²c˜‹§ ~áäÆL#f?â¶ŠªþU™á˜ÉÉOæ{^¤ëaÀ Tê"1Û¨Dtî’œxˆk‘:@ŽD5î:'¶e\*³q‘׸`…±¾ôäó÷ð1j7þä‘åQ6®9bcxã„A2ã—-ÇøüåÉò÷2{ÂÐe桢ǙŒÄg©Az!Ø¡>±zךÂ+;f RZÛÝ€ížáÒžHa¬¢Æ'ë•ñ þ=Ð=ºtyšÖâå'ÇpžÄ¦ÆN½€5½roåðFe¹)ˆš`ØnhŠy(GÆÔ} Bu7H¥JzÐ iVê÷áÆ”øG>6HÿUµÞhµj YH-ÌaaEÚx±‰…Êâ£-ûeÎqCÆLÌå㘎‰†LÐÆM I]€a)Ï.$—ÅH••£ ŒŒ’ªÉ;cŽc(i´¥!I]‹€„³tFc^ë'€e±øÉ_øß

Here is my code:

$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://www.thesite.com/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);
print $result; 

Any help would be great,

Thanks!

4
  • So what URL are you requesting? Have you tried requesting it in the browser with a blank user agent? What do you get? Commented May 20, 2011 at 1:18
  • The url isn't important because it will be changed often, I'm just looking to grab all the HTML in the document I point the curl to. Commented May 20, 2011 at 1:19
  • Do you get headers back? Check out the Content-Encoding header. the body may be compressed. If you're not even getting headers back, are you sure you're connecting to an HTTP server? Commented May 20, 2011 at 1:27
  • Could you explain a little more? Commented May 20, 2011 at 1:28

1 Answer 1

2

If the response is GZIP'd, you may use this:

curl_setopt($curl, CURLOPT_ENCODING, 'gzip');

See: http://www.php.net/manual/en/function.curl-setopt.php

To see if it's gzip'd, check the headers (see CURLOPT_HEADER).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.