How to get web-page-title with CURL in PHP from we

2019-08-09 19:56发布

I want to store the title in UTF—8,but the pages comes up with many different charset,such as GBK,ISO,unicode……

Could you give me some help?

Thanks.

1条回答
男人必须洒脱
2楼-- · 2019-08-09 20:26

Identify or detect the character encoding and convert the data to UTF-8 if necessary.

For HTML (i.e. text/html) there are three ways to specify the character encoding:

  1. An HTTP "charset" parameter in a "Content-Type" field.
  2. A META declaration with "http-equiv" set to "Content-Type" and a value set for "charset".
  3. The charset attribute set on an element that designates an external resource.

If neither of these is present, you might do some content sniffing or switch to some default character encoding (e.g. ISO 8859-1).

If the identified/detected character encoding is not UTF-8, you then can convert the data to UTF-8 with iconv or mb_convert_encoding.

查看更多
登录 后发表回答