I'm using file_get_contents() to get HTML and scrap some data from a website. The source is not always UTF8 but I am using the FORCEUTF8 class to fix it. It doesn't work fine though. What am I doing wrong?
/* Load UTF8 HTML */
require_once('/ForceUTF8/Encoding.php');
use \ForceUTF8\Encoding;
function loadHTMLInUtf8($url){
$utf8_or_latin1_or_mixed_string=file_get_contents($url);
return Encoding::toUTF8($utf8_or_latin1_or_mixed_string);
}
$html=loadHTMLInUtf8('http://www.example.com/');
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$html);
Is there an alternative way of doing this?