如何从PHP的不同CHARSET的网站获取网页标题与CURL? [英] How to get web-page-title with CURL in PHP from web-sites of different CHARSET?

查看:227
本文介绍了如何从PHP的不同CHARSET的网站获取网页标题与CURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以UTF-8存储标题,但页面上出现许多不同的字符集,如GBK,ISO,unicode ......

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

给我一些帮助?

感谢。

推荐答案

对于HTML(即text / html),有三种指定字符编码的方法

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



  1. Content-Type字段中的HTTPcharset参数。

  2. A META
  3. 字符集 / code>声明http-equiv设置为Content-Type code>在指定外部资源的元素上设置属性。

  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.


这些是存在的,你可以做一些内容嗅探或切换到一些默认的字符编码(例如ISO 8859-1)。

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

如果识别/检测的字符编码不是UTF -8,然后可以使用 iconv 将数据转换为UTF-8 / a>或 mb_convert_encoding

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.

这篇关于如何从PHP的不同CHARSET的网站获取网页标题与CURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆