瓜西西

导航

simple_html_dom.php 的使用

simple_html_dom.php 可以说使用PHP处理 网页, html 还可以.

 

不过, 与java 处理 不同的网页编码一样,  对不同的编码并没有进行处理,  已进行了改进. 以下是使用方法:
(说明: 目前只修改为读取 UTF8 或 gb2312 网页.)

 

g/fw.php 中, 以下定义与 simple_html_dom 有关:

$MY_HTML_CONV = "utf8->gb";  // 这是读取UTF8编码时的设置.

$IS_CURL = true;     // 使用 curl 读取,  还是使用 file_get_contents读取网页.

$IS_CONV = true;   // 使用 iconv() 还是使用 mb_convert_encoding 进行转码  <<-- 这与 simple_html_dom 无关

---------------------------------------------------------------------------------

注:  如果在一个函数中, 要读取gb2312 的编码, 而已经在 $MY_HTML_CONV 中指定的是读取 UTF8 编码的话, 要使用如下:

include('simplehtmldom/simple_html_dom.php');

 

// 读取 GB2312 的网页内容.
$GLOBALS['MY_HTML_CONV'] = null;  // 注: 这行是为了修改在 g/fw.php 中已定义的值.
$html = str_get_html($ct);

---------------------------------------------------------------------------------

posted on 2012-06-08 17:43  瓜西西  阅读(490)  评论(0编辑  收藏  举报