이 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로 변환하려면 어떻게해야합니까? 감사.
이 '에 정교한하시기 바랍니다 인코딩이 잘못 '. 또한 빠른 테스트 결과 utf8에서 페이지가 제공됩니다. – Maerlyn
mb_detect_encoding ($ textNodeContent, 'iso-8859-2, iso-8859-1, utf-8')은 iso-8859-2를 반환합니다. $ textNodeContent를 인쇄 할 때 제대로 표시되지 않습니다. – turbod
왜 처음에는'iconv()'입니까? 인코딩은 이미 시작부터 utf-8이어야합니다. –