将csv文件打开到wordpad中后,我不希望字段名用双引号引起来 [英] After opening csv file into wordpad ,i don't want double quotes for the field name

查看:114
本文介绍了将csv文件打开到wordpad中后,我不希望字段名用双引号引起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将数据导出到csv文件并使用写字板myfield打开文件时,Sr.No.看起来像"Sr. No."我不希望用双引号引起来.代码如下.

When I export data to csv file and open file with wordpad myfield Sr. No. looks like "Sr. No." .I don't want it in double quotes.Code is as follow.

        $filename = "file.csv";
        $fp = fopen('php://output', 'w');           
        $array = array('Sr. No.','Name','DOB','Address');
        $header = str_replace('',' ', $array);
        header('Content-type: application/csv');
        header('Content-Disposition: attachment; filename='.$filename);
        fputcsv($fp, $header);
        $query = "select * from registratin";
        $result = mssql_query($query);
        $i = 1;
        while($row = mssql_fetch_row($result)) {
          $row = array_merge(array($i), $row);
          fputcsv($fp, $row);
          $i++;
        }

推荐答案

您确实意识到CSV文件的格式实际上是吗?如果这些字符串包含非字母字符,它们应该用引号引起来吗? PHP的fputcsv()函数完全可以实现此目的

You do realise what the format for a CSV File actually is don't you? That strings are meant to be wrapped in quotes if they contain non-alpha characters? And PHP's fputcsv() function does this, exactly as it's supposed to

尽管您可以将 fputcsv()的附件参数设置为告诉它在引号/附件中应使用什么字符.

Although you can set the enclosure argument for fputcsv() to tell it what character should be used for quotes/enclosures.

例如

fputcsv($fp, $row, ",", "'");

使用单引号而不是双引号,或

To use a single quote instead of double quotes, or

fputcsv($fp, $row, ",", " ");

使用空格

这篇关于将csv文件打开到wordpad中后,我不希望字段名用双引号引起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆