Php 货币英镑显示为&;英镑导出为csv时
我需要将数据导出为csv。除了货币符号,一切都在变。 例如,货币英镑显示为Php 货币英镑显示为&;英镑导出为csv时,php,laravel,csv,export-to-csv,laravel-4.2,Php,Laravel,Csv,Export To Csv,Laravel 4.2,我需要将数据导出为csv。除了货币符号,一切都在变。 例如,货币英镑显示为&英镑 我的项目是一个Laravel4.2应用程序 $filename = $customer['firstname']."_".date('Y-m-d h:i').".csv"; $file_path = storage_path(). "/transactions"."/".$filename; $handle = fopen($file_path,"w+"); fputcsv($handle, ar
&英镑代码>
我的项目是一个Laravel4.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实体转换为UTF-8字符:
以下是一个例子:
$currency = '£';
echo $currency, PHP_EOL;
echo html_entity_decode($currency, ENT_HTML5, 'utf-8'), PHP_EOL;
产出:
£
£
导出时,请尝试使用编码UTF-8。我已更新了问题。请检查并告诉我必须更改的位置尝试此'Content-Type'=>text/csv charset=UTF-8
数据来自何处-来自数据库?您是否将“£;”存储在数据库中?┬ú这是我在csv文件中看到的。我只是下载文件并在您用来读取它的软件中查看,您能将编码更改为UTF-8吗?您还可以根据默认编码更改html\u entity\u decode()
(最后一个参数)的编码。
£
£