Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6065369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:22:57+00:00 2026-05-23T09:22:57+00:00

I’m trying to write my own web crawler with cURL in PHP. […] mb_internal_encoding(‘UTF-8’);

  • 0

I’m trying to write my own web crawler with cURL in PHP.

[...]
mb_internal_encoding('UTF-8');
mb_language('uni');
$this->_curl = curl_init();
curl_setopt($this->_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->_curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->_curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($this->_curl, CURLOPT_MAXREDIRS, 0);
curl_setopt($this->_curl, CURLOPT_TIMEOUT, 10);
curl_setopt($this->_curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10');
curl_setopt($this->_curl, CURLOPT_HEADER, true);
curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
$header = array(
            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
            "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
            "Keep-Alive: 115",
            "Connection: keep-alive",
);
curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($this->_curl, CURLOPT_URL, $url);
curl_setopt($this->_curl, CURLOPT_POST, false);
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, array());
curl_setopt($this->_curl, CURLOPT_HTTPGET, true);
$page = curl_exec($this->_curl);
[...]

The problem is the charset of the website. As you can see on

http://blog.163.com/drewes_4711/blog/static/179317021201151624826557/

there is a header "Content-Type: ...;charset=GBK" so I can do mb_convert_encoding($content, "UTF-8", "GBK"); but what should I do with

http://tech.hexun.com/2011-06-21/130756909.html

It seems to be the same charset, but it’s not given in HTTP header. So I have massive problems with german umlauts, chinese and asian languages… Is there any module or snippet that I can use to determine the charset of ANY downloaded HTML site with cURL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:22:57+00:00Added an answer on May 23, 2026 at 9:22 am

    That second link contains:

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    

    All data before that looks like plain ASCII. So you could try, if the HTTP headers don’t give a clue, just parsing (assuming plain ASCII, not UTF-8 – that’s likely to break) until you find that header.

    This is obviously not guaranteed to work. If the server doesn’t send the encoding, and the page doesn’t have that header either, you’re out of luck. There are no universal means to detect the encoding of a given piece of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.