2010-07-10 6 views
0

이 URL의 콘텐츠를 가져 오려고 시도합니다 : http://www.chromeball.com,하지만 문자 인코딩이 좋지 않습니다.문자 인코딩 오류!

이 코드가 있습니다

$url = 'http://www.chromeball.com'; 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
$data = curl_exec($ch); 
curl_close($ch); 


$dom = new DOMDocument(); 
$dom->loadHTML($data); 
$xpath = new DOMXPath($dom); 
$nodes = $xpath->query('//text() | //@alt | //@title | /html/head/meta[@name="description"] | /html/head/meta[@name="keywords"]'); 
foreach($nodes as $node) { 
    $textNodeContent .= " ".$node->nodeValue; 
} 

$enc = mb_detect_encoding($textNodeContent,'iso-8859-2,iso-8859-1,utf-8'); 
print iconv($enc,'utf-8//TRANSLIT',$textNodeContent); 

을하지만이 작동하지 않습니다. 문자 인코딩이 잘못되었습니다. $ textNodeContent를 utf-8로 변환하려면 어떻게해야합니까? 감사.

+0

이 '에 정교한하시기 바랍니다 인코딩이 잘못 '. 또한 빠른 테스트 결과 utf8에서 페이지가 제공됩니다. – Maerlyn

+0

mb_detect_encoding ($ textNodeContent, 'iso-8859-2, iso-8859-1, utf-8')은 iso-8859-2를 반환합니다. $ textNodeContent를 인쇄 할 때 제대로 표시되지 않습니다. – turbod

+0

왜 처음에는'iconv()'입니까? 인코딩은 이미 시작부터 utf-8이어야합니다. –

답변

0

mb_detect_encoding 페이지의 의견에서 기능이 특히 안정적이지 않은 것처럼 보입니다. Chrigu (참조 포스트 년 29 월 2005 년 3시 32분), 목록의 첫 번째 문자 인코딩으로 UTF-8을 배치 제안 :

$enc = mb_detect_encoding($textNodeContent,'utf-8,iso-8859-2,iso-8859-1'); 

나는 그것을 시도했습니다, 그리고 지금있는 UTF-과 내용을 보여줍니다 8. 그러나, 나는 단지 ISO-8859-1 컨텐츠와 그것을 시도했습니다, 그리고 UTF-8도 ... 이런

+0

감사합니다.하지만 내용을 인쇄하려고하면 제대로 표시되지 않습니다. – turbod

0

초기화 DOM으로 감지 :

$dom->loadHTML('<?xml encoding="UTF-8">' . $data); 
+0

불행히도 문제가 해결되지 않았습니다. – turbod