gpt4 book ai didi

PHP使用PHPExcel lib读取具有非英文内容的excel文件

转载 作者:行者123 更新时间:2023-12-04 21:07:34 24 4
gpt4 key购买 nike

我有一个包含非英语内容(俄语)的 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
)

但原来的值(value)是这样的,
Бесплатный переводчик , перевод , Бесплатный словарь Интернет

最佳答案

查找 fputcsv (或 xlsx 的类似函数)在您的 excel 库代码中调用。启用所有必要的参数

int fputcsv(资源 $handle ,
数组 $fields [,
字符串 $delimiter = ","[,
字符串 $enclosure = '"' [, 字符串 $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 起着重要的作用。

如果您将字符串//TRANSLIT 附加到 out_charset 音译被激活。这意味着当一个字符不能在目标字符集中表示时,它可以通过一个或几个看起来相似的字符来近似。如果附加字符串//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)

和更多字符集谷歌它......

查看更多信息,
[http://php.net/manual/en/function.iconv.php][1]

[http://en.wikipedia.org/wiki/Character_encoding][2]

关于PHP使用PHPExcel lib读取具有非英文内容的excel文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30527303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com