function convertToUTF8($file, $charSet, $char_Set, $converter_dir) { global $home_charset; $conv_file = $file; // pure code if (stristr($charSet, "WINDOWS-31J")) { // $charSet = 'cp936'; // use cp936, which is equal to WINDOWS-31J } $iconv_file = @iconv($charSet, "UTF-8//IGNORE", $conv_file); // if installed, first try to use PHP function iconv() // IGNORE => ignore unknown characters // TRANSLIT=> replace unknown characters with something similar // Attention: TRANSLIT breaks converting, if no 'close to' chararacter will be found //echo "\r\n\r\n<br /> iconv_file: $iconv_file<br />"; if (trim($iconv_file) == "") { // iconv is not installed or input charSet not available. We need to use class ConvertCharset $char_Set = str_ireplace('iso-', '', $charSet); //$charSet = str_ireplace ('iso','',$charSet); $converter = "" . $converter_dir . "/charsets/" . $char_Set . ".txt"; if (!is_file($converter)) { // if this charset table is not avaulable $char_Set = str_ireplace('iso-', '', $home_charset); // try alternatively the home charset printConverterError($charSet, $cl); printTryHome($home_charset, $cl); } if (is_file($converter) || $home_charset != 'UTF-8') { // UTF-8 -> UTF-8 would not work $NewEncoding = new ConvertCharset($char_Set, "utf-8"); $NewFileOutput = $NewEncoding->Convert($conv_file); //$NewEncoding = new ConvertCharset; //$NewFileOutput = $NewEncoding->Convert($conv_file, $chrSet, "utf-8",false); $file = $NewFileOutput; } } else { $file = $iconv_file; } unset($conv_file, $iconv_file, $NewEncoding, $NewFileOutput); return $file; }
function MakeConvertTable($FromCharset, $ToCharset = '') { global $home_charset, $cl, $command_line, $no_log; $ConvertTable = array(); for ($i = 0; $i < func_num_args(); $i++) { $FileName = func_get_arg($i); $FileName = "{$FileName}.txt"; if (!is_file(CONVERT_TABLES_DIR . $FileName)) { //print $this -> DebugOutput(0, 0, CONVERT_TABLES_DIR . $FileName); //Print an error message printConverterError($FileName, $cl); printTryHome($home_charset, $cl); $homeSet = str_ireplace('iso-', '', $home_charset); //$homeSet = str_ireplace ('iso','',$home_charset); $FileName = "{$homeSet}.txt"; if (!is_file(CONVERT_TABLES_DIR . $FileName)) { //print $this -> DebugOutput(0, 0, CONVERT_TABLES_DIR . $FileName); //Print an error message printConverterError($FileName, $cl); printStandardReport('abortedIndx', $command_line, $no_log); //echo "<p class='evrow'><a class='bkbtn' href='admin.php' title='Go back to Admin'>Back to admin</a></p>"; return ''; } } $FileWithEncTabe = fopen(CONVERT_TABLES_DIR . $FileName, "r") or die; //This die(); is just to make sure... while (!feof($FileWithEncTabe)) { if ($OneLine = trim(fgets($FileWithEncTabe, 1024))) { if (substr($OneLine, 0, 1) != "#") { $HexValue = preg_split("/[\\s,]+/", $OneLine, 3); //We need only first 2 values if (substr($HexValue[1], 0, 1) != "#") { $ArrayKey = strtoupper(str_replace(strtolower("0x"), "", $HexValue[1])); $ArrayValue = strtoupper(str_replace(strtolower("0x"), "", $HexValue[0])); $ConvertTable[func_get_arg($i)][$ArrayKey] = $ArrayValue; } } } } } if (!is_array($ConvertTable[$FromCharset])) { $ConvertTable[$FromCharset] = array(); } if (func_num_args() > 1 && count($ConvertTable[$FromCharset]) == count($ConvertTable[$ToCharset]) && count(array_diff_assoc($ConvertTable[$FromCharset], $ConvertTable[$ToCharset])) == 0) { print $this->DebugOutput(1, 1, "{$FromCharset}, {$ToCharset}"); } return $ConvertTable; }