donglun2024 2014-06-27 11:45
浏览 19

PHP到csv分号问题

I have the following $data array:

array(
    (int) 0 => '37899810;214214;01;5083;;',
    (int) 1 => '37899810;214215;01;19966;;',
    (int) 2 => '37899810;54654;01;35691;;',
    (int) 3 => '37899810;769;01;52016;;'
)

When I try to echo it as csv in the following way:

foreach($data as $row):
    echo $row."
";
endforeach;

For each and every row, the semi-colons are escaped and integers are put into different cells. What I want to get instead, is the whole string, let's say 37899810;214214;01;5083;; to be placed in one cell, and that the remaining ones would be placed in the other rows, but the strings would just take one cell.

  • 写回答

1条回答 默认 最新

  • dongzhaoshi8497 2014-06-27 12:14
    关注

    try this

    header( 'Content-Type: text/csv' );
    header( 'Content-Disposition: attachment;filename=example.csv');
    $handle = fopen('php://output', 'r+');
    foreach ($data as $row) {
       fputcsv($handle, $row, ';');
    }
    fclose($handle);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)