doumi0737 2016-03-22 12:11
浏览 445
已采纳

PHP - CSV导出 - 在列数据中添加逗号

I am exporting data to CSV and facing one problem.

$data['name'] = "Test";
$data['category'] = "category1, category2, caegory3";

When I export code to CSV, it exports records but make separate column for category1, separate column for category 2 and separate column for category3.

Current Output
-------------------------------------------
| Name | Category  |           |           |
-------------------------------------------- 
| TEst | category1 | category2 | category3 |
--------------------------------------------


 Expected Output

------------------------------------------------------------
| Name | Category                      |         |         |
-------------------------------------------- ---------------
| TEst | category1,category2,category3 |         |         |
------------------------------------------------------------

What should I do so comma-separated String fall in same column?

  • 写回答

2条回答 默认 最新

  • dtnd30892 2016-03-22 12:12
    关注

    You should have category values between "" so the comma is not interpreted. You can change code like this:

    $data['name'] = 'Test';
    $data['category'] = '"category1, category2, caegory3"';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?