Hi! I try get the content this URL: http://www.chromeball.com, but the character encoding is not good.
I have this code:
$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);
But this not working. The character encoding is wrong. How can i convert the $textNodeContent to utf-8? Thanks.