Grasp.Today

HTML如何转XTML

 1 ob_start();
 2 $html = curl_init('http://www.beijing.gov.cn/');
 3 curl_exec($html);
 4 $html = iconv('GBK','UTF-8',$html);
 5 $config = array('indent' => TRUE,
 6     'output-xhtml' => TRUE,
 7     'wrap' => 200);
 8 $tidy = tidy_parse_string($html,$config,'UTF8');
 9 $tidy->cleanRepair();
10 $tidyhtml = (string)$tidy;
11 $xml = simplexml_load_string($tidyhtml);
12 echo $tidyhtml;
13 var_dump($xml);
View Code

 

posted @ 2013-07-13 23:27  gaohj  阅读(233)  评论(0编辑  收藏  举报