-phpQueryééåºç°ä¹±ç
程序员文章站
2022-06-11 19:12:08
...
å¨çº¿ç-phpQueryééåºç°ä¹±ç
å ³äºééçµå½±å¤©å åºç°ä¹±ç ï¼æ±é«æ帮å¤çãããããããã
header("Content-type: text/html; charset=utf-8");
set_time_limit(0);
require_once("../phpQuery/phpQuery.php");
function shootCodeBug($data){
$data=mb_convert_encoding($data,'ISO-8859-1','gb2312');
return mb_convert_encoding($data,'utf-8','GBK');
}
phpQuery::newDocumentHTML(shootCodeBug('http://www.dytt8.net/'));
phpQuery::$defaultCharset="gb2312";
$content = pq("#menu")->html();
phpQuery::$documents=array(); //æ¸ ç©ºç¼å
------解å³æè·¯----------------------
è¿æ¯ä½ ç使ç¨æ¹æ³ä¸å½é æç
phpQuery æ¯å©ç¨ DOMDocument å HTML 解æç
è DOMDocument::loadHTML æ¹æ³å¨è½½å ¥ HTML æ°æ®æ¶ï¼ä¼æ ¹æ®ææ¡£ä¸ç æ è®°æ¥è¯å«ææ¡£çå符éã
å¦æææ¡£ä¸æ²¡æè¿ä¸ªæ è®°ï¼ååé»è®¤å符é ISO-8859-1
å æ¤ï¼å¦æå¾ å¤ççå 容没æå符é声ææ è®°æ¶ï¼åºèªå·±éå ä¸å»
设 $html ä¸ºå¾ åæçå 容ï¼å
å½ç¶ï¼ä½ ä¹å¯ä»¥æ´ä½ç转æ¢æ utf-8 ç¼ç ç
å ³äºééçµå½±å¤©å åºç°ä¹±ç ï¼æ±é«æ帮å¤çãããããããã
header("Content-type: text/html; charset=utf-8");
set_time_limit(0);
require_once("../phpQuery/phpQuery.php");
function shootCodeBug($data){
$data=mb_convert_encoding($data,'ISO-8859-1','gb2312');
return mb_convert_encoding($data,'utf-8','GBK');
}
phpQuery::newDocumentHTML(shootCodeBug('http://www.dytt8.net/'));
phpQuery::$defaultCharset="gb2312";
$content = pq("#menu")->html();
phpQuery::$documents=array(); //æ¸ ç©ºç¼å
------解å³æè·¯----------------------
è¿æ¯ä½ ç使ç¨æ¹æ³ä¸å½é æç
phpQuery æ¯å©ç¨ DOMDocument å HTML 解æç
è DOMDocument::loadHTML æ¹æ³å¨è½½å ¥ HTML æ°æ®æ¶ï¼ä¼æ ¹æ®ææ¡£ä¸ç æ è®°æ¥è¯å«ææ¡£çå符éã
å¦æææ¡£ä¸æ²¡æè¿ä¸ªæ è®°ï¼ååé»è®¤å符é ISO-8859-1
å æ¤ï¼å¦æå¾ å¤ççå 容没æå符é声ææ è®°æ¶ï¼åºèªå·±éå ä¸å»
设 $html ä¸ºå¾ åæçå 容ï¼å
if(! preg_match('/]+charset=/i', $html)) {åç» phpQuery å¤ç就没æé®é¢äº
$charset = mb_check_encoding($html, 'utf-8') ? 'utf-8' : 'gbk';
$html = sprintf('%s', $charset, $html);
}
å½ç¶ï¼ä½ ä¹å¯ä»¥æ´ä½ç转æ¢æ utf-8 ç¼ç ç
声æï¼æ¬æå 容ç±ç½åèªåè´¡ç®ï¼çæå½åä½è ææï¼æ¬ç«ä¸æ¿æ ç¸åºæ³å¾è´£ä»»ãå¦æ¨åç°ææ¶å«æè¢ä¾µæçå 容ï¼è¯·èç³»admin@php.cnæ ¸å®å¤çã
ç¸å ³æç«
ç¸å ³è§é¢