public function convertToUtf8($text) {
if(!$this->html)
$this->html = cURL('http://'.$this->url, array('timeout' => 15));
$html = $this->html;
preg_match('/<meta.*?charset=(|\")(.*?)("|\")/i', $html, $matches);
$charset = $matches[2];
if($charset)
return mb_convert_encoding($text, 'UTF-8', $charset);
else
return $text;
}
cURL default options:
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
I tried something like this. It helped me. If found on meta charset info, I'm converting, otherwise doing nothing.