du9698 2015-04-21 06:00
浏览 100

使用php在csv文件中显示逗号

I have name,address and images stored in my database.on clicking "GENERATE EXCEL" button a .csv file will be generated.I am using comma as a separator.

my actual o/p should be like this:

name      address           images

peter   "house no#2",uk   img1.png,img2.png,img3.png

but currently i am getting the values with comma in different columns.how can i do this? please help.

this is my code fetching the values from the database:

 $sep = ",";
            $csv_hdr = "Name".$sep."Address".$sep."Images";
            $csv_output="";     
            for($i=$start;$i<$match;$i++)
            {
                $csv_output .=$ARRAY[$i]['source_name'].$sep;
                $i_add=str_replace('"',"",$ARRAY[$i]['source_address']);
                $csv_output.=$ARRAY[$i]['source_address'].$sep;
                $csv_output.=$ARRAY[$i]['source_img']."
";
            }

this is my 'GENERATE_EXCEL' button with 2 hidden fields csv header and data.

<div id="btnexcel">
        <input type="submit" name="Generate Excel" value="Generate Excel" id="btnreport" formaction="export_to_excel.php"/></div>
        <input type="hidden" value="<?php echo $csv_hdr; ?>" name="csv_hdr">
        <input type="hidden" value="<?php echo $csv_output; ?>" name="csv_output">

this is my export_to_excel.php:

<?php

$out = '';
        $filename_prefix = 'csv';
        if (isset($_GET['csv_hdr'])) {
        $out .= $_GET['csv_hdr'];
        $out .= "
";
}

if (isset($_GET['csv_output'])) {
$out .= $_GET['csv_output'];
}
$filename = $filename_prefix."_".date("Y-m-d_H-i",time());

//Generate the CSV file header
header("Content-type: application/vnd.ms-excel");
header("Content-Encoding: UTF-8");
header("Content-type: text/csv; charset=UTF-8");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
echo "\xEF\xBB\xBF"; // UTF-8 BOM
//Print the contents of out to the generated file.
print $out;

//Exit the script
exit;
?> 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端