gpt4 book ai didi

php - 导出为 csv 时,货币英镑显示为 £

转载 作者:行者123 更新时间:2023-12-02 20:28:13 25 4
gpt4 key购买 nike

我需要将数据导出为 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;

输出:

£
£

关于php - 导出为 csv 时,货币英镑显示为 £,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49383839/

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