问题
i am trying to modify my CSV export. But it wont convert / save my CSV from UTF-8 to ISO-8859-1
Any Ideas what i have made wrong, please?
Actually since modifying this, i get a empty CSV File...
(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;
}
SOLUTION:
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;
}
回答1:
The Solution as answer, as requested:
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;
}
来源:https://stackoverflow.com/questions/46118202/csv-from-utf8-to-iso-8859-1