我想修改我的CSV出口。 但它不会转换/从UTF-8我的CSV保存为ISO-8859-1
我所做出错误的任何想法,请?
实际上,因为修改此,我得到一个空的CSV文件...
(PHP的7.0.x)
function my_GenerateCSV($prefix, $csvarray, $getMonth){
### Generate CSV File from CSVArray
if ($prefix == 'sepa'){
$date = '-'.getTodaysDate();
}
$month = $getMonth;
$filename = 'private/'.$prefix.'-'.$month.$date.'.csv';
$fp = fopen(ROOTDIR . '/'.$filename, 'w');
foreach ($csvarray as $key => $value) {
//fputcsv($fp, $value, ';');
fputcsv($fp, convertToISOCharset($value), ';');
}
fclose($fp);
return $filename;
}
function convertToISOCharset($string) {
$string = mb_convert_encoding($string, "ISO-8859-1", "UFT-8");
return $string;
}
解:
function convertToISOCharset($array)
{
foreach($array as $key => $value)
{
if(is_array($value))
{
$array[$key] = convertToISOCharset($value);
}
else
{
$array[$key] = mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8');
}
}
return $array;
}