この 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 に変換するにはどうすればよいですか? ありがとう。