private function convertEncoding()
{
$exec = array();
exec('file -i "' . $this->filename . '"', $exec);
$res_exec = explode('=', $exec[0]);
if (empty($res_exec[1])) {
throw new \Exception('Unable to detect file encoding.');
}
$this->encoding = $res_exec[1];
$tmp_encoding = strtolower($this->encoding);
switch ($tmp_encoding) {
case 'unknown':
case 'windows-1252':
case 'iso-8859-1':
case 'iso-8859-15':
case 'us-ascii':
$this->encoding = self::default_encoding;
$this->file_content = self::cp1252_to_utf8($this->file_content);
break;
default:
if (strtolower(substr($this->encoding, 0, 3)) == 'utf' && self::detect_utf_encoding($this->file_content)) {
$this->has_BOM = true;
}
if (strtolower(substr($this->encoding, 0, 7)) == 'unknown') {
$this->encoding = self::default_encoding;
$this->file_content = self::cp1252_to_utf8($this->file_content);
} else {
$this->file_content = mb_convert_encoding($this->file_content, 'UTF-8', $this->encoding);
}
break;
}
}