PHP使用PHPExcel lib读取非英文内容的excel文件
我有一个包含非英文内容(俄语)的xlsx文件。 我正在使用PHPExcel lib来读取它。 当我读我的文件输出是完全搞砸了? 有没有什么办法解决这一问题 ? 我试图转换utf8,但没有运气。 任何帮助将不胜感激。 这是我的代码。
<?php include_once 'Classes/PHPExcel.php'; echo '<pre>'; $excelFile = "test.xlsx"; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load($excelFile); //Itrating through all the sheets in the excel workbook and storing the array data foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $arrayData[$worksheet->getTitle()] = $worksheet->toArray(); } /* function utf8_converter($arrayData) { array_walk_recursive($array, function(&$item, $key){ if(!mb_detect_encoding($item, 'utf-8', true)){ $item = utf8_encode($item); } }); return $arrayData; } utf8_converter($arrayData); */ print_r($arrayData); ?>
我的输出是,
[1] => Array ( [0] => 199 [1] => Clothing [2] => ru [3] => T shirt [4] => Ð'еÑплатный переводчик , перевод , Ð'еÑплатный Ñловарь Интернет [5] => Ð'еÑплатный переводчик , перевод , Ð'еÑплатный Ñловарь Интернет ) [2] => Array ( [0] => 203 [1] => Clothing [2] => ru [3] => pant [4] => Ð'еÑплатный переводчик , перевод , Ð'еÑплатный Ñловарь Интернет [5] => This test Short des )
但是原来的价值就好像,
Бесплатный переводчик , перевод , Бесплатный словарь Интернет
在您的excel库代码中查找fputcsv
(或xlsx的类似函数)调用。 启用所有必要的参数
int fputcsv(resource $ handle,array $ fields [,string $ delimiter =“,”[,string $ enclosure ='“',[string $ escape_char =”\“]]])
然后使用,
$text = "This is the Euro symbol '€'."; echo 'Original : ', $text, PHP_EOL; echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL; echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL; echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
这里out_charset起着重要的作用。
如果将string“TRANSLIT”附加到out_charset,则音译被激活。 这意味着当字符不能在目标字符集中表示时,它可以通过一个或几个相似的字符来近似。 如果追加string// IGNORE,则无法在目标字符集中表示的字符将被丢弃。 否则,生成E_NOTICE,函数将返回FALSE。
ISO 8859: ISO 8859-1 Western Europe ISO 8859-2 Western and Central Europe ISO 8859-3 Western Europe and South European (Turkish, Maltese plus Esperanto) ISO 8859-4 Western Europe and Baltic countries (Lithuania, Estonia, Latvia and Lapp) ISO 8859-5 Cyrillic alphabet ISO 8859-6 Arabic ISO 8859-7 Greek ISO 8859-8 Hebrew ISO 8859-9 Western Europe with amended Turkish character set ISO 8859-10 Western Europe with rationalised character set for Nordic languages, including complete Icelandic set ISO 8859-11 Thai ISO 8859-13 Baltic languages plus Polish ISO 8859-14 Celtic languages (Irish Gaelic, Scottish, Welsh) ISO 8859-15 Added the Euro sign and other rationalisations to ISO 8859-1 ISO 8859-16 Central, Eastern and Southern European languages (Albanian, Bosnian, Croatian, Hungarian, Polish, Romanian, Serbian and Slovenian, but also French, German, Italian and Irish Gaelic)
和更多的字符集Google呢…
检查更多的信息,
[http://php.net/manual/en/function.iconv.php][1] [http://en.wikipedia.org/wiki/Character_encoding][2]