亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 在 Excel 的 .csv 中編碼變音符號

PHP 在 Excel 的 .csv 中編碼變音符號

PHP
白板的微信 2023-10-15 15:45:19
我正在編寫一個 PHP 腳本,該腳本根據一些數據創建 .csv 文件。不幸的是,在 Excel 中變音符號無法正確顯示:L?l變成L√?l(這只是在 Excel 中,在 Apple 的 Numbers、Atom 和 Textedit 中一切看起來都很好)。我已經嘗試了數百個函數來嘗試獲得正確的編碼(請參閱下面的注釋函數)。有人可以告訴我我做錯了什么嗎?$rows = json_decode('[["L?l"]]');foreach($rows as $key_row => $row) {  foreach($row as $key_cell => $cell) {    // $rows[$key_row][$key_cell] = utf8_decode($cell);    // $rows[$key_row][$key_cell] = iconv('UTF-8', 'Windows-1252', $cell);    // $rows[$key_row][$key_cell] = mb_convert_encoding($cell, 'UTF-16LE', 'UTF-8');    // iconv('UTF-8', 'Windows-1252', $rows[$key_row][$key_cell]);    // mb_convert_encoding($rows[$key_row][$key_cell], 'UTF-16LE', 'UTF-8');  }}$temp = fopen('php://memory', 'w');foreach($rows as $row) {  fputcsv($temp, $row, ';'); }fseek($temp, 0);header('Content-Type: application/csv');header('Content-Disposition: attachment; filename="test.csv";');fpassthru($temp);
查看完整描述

1 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

以下轉換UTF-8 BOM有效:


foreach($rows as $key_row => $row) {

  foreach($row as $key_cell => $cell) {

    $rows[$key_row][$key_cell] = chr(239) . chr(187) . chr(191) . $cell;

  }

}

感謝所有參與的人:)


查看完整回答
反對 回復 2023-10-15
  • 1 回答
  • 0 關注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號