How can I fix ebay garbled data collected by curl?

Source: Internet
Author: User
How can I solve the problem of collecting ebay garbled codes with curl? Dear friends, I have used curl to collect information and found that the information collected from ebay stores is always garbled, for example, $ urlstores. ebay. comsportingamerica; $ caijicurl_get_contents ($ url); print_r ($ caiji); can anyone explain this? Thank you! Function & ask curl How to collect ebay garbled code?
Dear friends, I have used curl to collect information and found that the information collected from ebay stores is always garbled, for example:

$ Url = "http://stores.ebay.com/sportingamerica ";
$ Caiji = curl_get_contents ($ url );
Print_r ($ caiji );
Can anyone explain this? Thank you!

Function curl_get_contents ($ url)
{
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
// Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 5 );
Curl_setopt ($ ch, CURLOPT_USERAGENT, _ USERAGENT _);
Curl_setopt ($ ch, CURLOPT_REFERER, _ REFERER _);
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ R = curl_exec ($ ch );
Curl_close ($ ch );
Return $ r;
}

There should be no problem with Encoding. My php file is encoded in UTF-8 and the ebay page is encoded in UTF-8.


------ Solution ----------------------
The data is compressed by gzip.

Set this curl_setopt ($ ch, CURLOPT_ENCODING, 1 );
Or echo gzdecode ($ caiji) after reading back );


------ Solution ----------------------
You can set the returned code encoding format to text/utf8.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.