日期:2014-05-17 浏览次数:20568 次
#网址:http://data.shishicai.cn/cqssc/haoma/
#Demo:
<?php
/* Created on [2013-5-1] Author[Newton] Filename[action.php]*/
#编码转换
function convToUtf8($str) {
if (mb_detect_encoding($str, "UTF-8, ISO-8859-1, GBK") != "UTF-8") {
return iconv("GBK", "utf-8", $str);
} else {
return $str;
}
}
header("content-type:text/html;charset:utf-8");
error_reporting(E_ERROR);
$pages = file_get_contents('http://data.shishicai.cn/cqssc/haoma/');
//$pages = htmlspecialchars($pages);
$pages = convToUtf8($pages);
echo "pages-->>".print_r($pages);echo PHP_EOL;
$doc = new DOMDocument();
$new_doc = new DOMDocument('1.0', 'utf-8');
echo "doc-->>".print_r($doc);echo PHP_EOL;
$dom = $doc->getElementsByTagName('table');
$newdoc = $new_doc->loadhtml($dom->item(2)->nodeValue);
$table = $new_doc->saveHTML();
echo "table-->>{$table}".PHP_EOL;
#result:
#……乱码……
#pages-->>1 DOMDocument Object ( ) doc-->>1 table-->>
#table是空的……
?>