导出为 csv 时,货币英镑显示为 £
currency pound is shown as £ when exporting as csv
我需要将数据导出为 csv。除了货币符号,一切都在变。
例如。货币 £ 显示为 £
我的项目是一个 laravel 4.2 应用程序。
$filename = $customer['firstname']."_".date('Y-m-d h:i').".csv";
$file_path = storage_path(). "/transactions"."/".$filename;
$handle = fopen($file_path,"w+");
fputcsv($handle, array('Date', 'Type', 'Ticket', 'Quantity', 'Ticket type', 'Block', 'Event date', 'Paid', 'Recieved'));
foreach($ticket as $row) {
if($row->type == 'purchased')
{
$p_amount = trans('homepage.currencyInUse') .' '.number_format($row->amount, 2).' '.trans('homepage.currencyAfter');
$s_amount = ' ';
}
elseif($row->type == 'sold')
{
$p_amount = ' ';
$s_amount = trans('homepage.currencyInUse').' '.number_format($row->amount, 2).' '.trans('homepage.currencyAfter');
}
fputcsv($handle, array(
date('d/m/Y', strtotime($row->orderDate)),
$row->type,
$row->event->title,
$row->qty,
$row->ticketType,
trans('homepage.Block').':'.$row->ticket['ticketInformation']['loc_block'] ,
date('d/m/Y', strtotime($row->event->datetime)),
$p_amount,
$s_amount,
)
);
}
fclose($handle);
$headers = array(
'Content-Type' => 'text/csv',
);
return Response::download($file_path, $filename, $headers);
这是用于导出为 csv 的代码
您可以使用 html_entity_decode()
:
将 HTML 个实体转换为 UTF-8 字符
$currency_use = html_entity_decode(trans('homepage.currencyInUse'), ENT_HTML5, 'utf-8');
$currency_after = html_entity_decode(trans('homepage.currencyAfter'), ENT_HTML5, 'utf-8');
if($row->type == 'purchased')
{
$p_amount = $currency_use.' '.number_format($row->amount, 2).' '.$currency_after;
$s_amount = ' ';
}
elseif($row->type == 'sold')
{
$p_amount = ' ';
$s_amount = $currency_use.' '.number_format($row->amount, 2).' '.$currency_after;
}
这是一个例子:
$currency = '£';
echo $currency, PHP_EOL;
echo html_entity_decode($currency, ENT_HTML5, 'utf-8'), PHP_EOL;
输出:
£
£
我需要将数据导出为 csv。除了货币符号,一切都在变。
例如。货币 £ 显示为 £
我的项目是一个 laravel 4.2 应用程序。
$filename = $customer['firstname']."_".date('Y-m-d h:i').".csv";
$file_path = storage_path(). "/transactions"."/".$filename;
$handle = fopen($file_path,"w+");
fputcsv($handle, array('Date', 'Type', 'Ticket', 'Quantity', 'Ticket type', 'Block', 'Event date', 'Paid', 'Recieved'));
foreach($ticket as $row) {
if($row->type == 'purchased')
{
$p_amount = trans('homepage.currencyInUse') .' '.number_format($row->amount, 2).' '.trans('homepage.currencyAfter');
$s_amount = ' ';
}
elseif($row->type == 'sold')
{
$p_amount = ' ';
$s_amount = trans('homepage.currencyInUse').' '.number_format($row->amount, 2).' '.trans('homepage.currencyAfter');
}
fputcsv($handle, array(
date('d/m/Y', strtotime($row->orderDate)),
$row->type,
$row->event->title,
$row->qty,
$row->ticketType,
trans('homepage.Block').':'.$row->ticket['ticketInformation']['loc_block'] ,
date('d/m/Y', strtotime($row->event->datetime)),
$p_amount,
$s_amount,
)
);
}
fclose($handle);
$headers = array(
'Content-Type' => 'text/csv',
);
return Response::download($file_path, $filename, $headers);
这是用于导出为 csv 的代码
您可以使用 html_entity_decode()
:
$currency_use = html_entity_decode(trans('homepage.currencyInUse'), ENT_HTML5, 'utf-8');
$currency_after = html_entity_decode(trans('homepage.currencyAfter'), ENT_HTML5, 'utf-8');
if($row->type == 'purchased')
{
$p_amount = $currency_use.' '.number_format($row->amount, 2).' '.$currency_after;
$s_amount = ' ';
}
elseif($row->type == 'sold')
{
$p_amount = ' ';
$s_amount = $currency_use.' '.number_format($row->amount, 2).' '.$currency_after;
}
这是一个例子:
$currency = '£';
echo $currency, PHP_EOL;
echo html_entity_decode($currency, ENT_HTML5, 'utf-8'), PHP_EOL;
输出:
£
£