php export / generate csv

2010-10-12  来源:本站原创  分类:PHP  人气:152 

php5

<?php
//1. Mainly set header file, set the text type
  header("Content-Type:application/csv");
//2.filename=xxx.csv  File name
  header("Content-Disposition:attachment;filename=abc.csv");
//3.  Use the/include    The contents of a cell, the contents of the double quotes    Swap two double quotation marks  ,  Wrap used  \n \r  All rows
  foreach($keys as $key){
        if(is_string($key))
                echo $key.",";
  }
  echo "\n";
  foreach($products as $product)
  {
        foreach($product as $key=>$value){
                if(is_string($key))
                        echo "\"".str_replace('"','""',$value)."\"".",";
        }
        echo "\n";
  }
?>

Problems encountered
1. The contents of the cell line, csv file line
3. Cell contents are comma, csv file split the cell
3. Cell contents are double quotes, csv file will first double quote "eat."

Two questions before the \ "contains the cell contents can be solved,
The third issue to replace a single quote two months, csv file to show only one.

Information to Department:
http://blog.5d.cn/user6/tile/200507/124121.html
http://witmax.cn/php-write-csv.html

相关文章
  • php export / generate csv 2010-10-12

    php5 <?php //1. Mainly set header file, set the text type header("Content-Type:application/csv"); //2.filename=xxx.csv File name header("Content-Disposition:attachment;filename=abc.csv"); //3. Use the/include The contents of a cell,

  • php generate CSV or Excel 2010-03-23

    1, making a simple Excel <?php header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=php2excel.xls"); echo "A1\t B1\t C1\n"; echo "A2\t B2\t C2\n"; echo "A3\t B3\t C3\n";

  • Bash to use MySQL data import and export in CSV format 2010-09-17

    MySQL export data in CSV format sample SQL statement is as follows: Java code select * from test_info into outfile '/ tmp / test.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\ r \ n'; select * from

  • Perl of xml file and generate csv data file, and write the database 2010-05-25

    #!/usr/bin/perl use XML::Simple; use Data::Dumper; use DBI; use Encode; use strict; use encoding "gbk"; # Determine whether passing XML file parameters if (open(MYFILE, "$ARGV[0]")) { # here's what to do if the file opened successfully

  • Opencsv generate csv file 2010-07-01

    public void testPersonService () ( List <String> filecon = new ArrayList <String> (); String m = ""; BufferedReader file; try ( file = new BufferedReader (new FileReader ("a.txt")); try ( while ((m = file.readLine ())! = nu

  • Generate csv avoid scientific notation 2010-09-27

    The data of each output by adding a tab \ t can be avoided in scientific notation

  • How pl / sql Developer in the query result set to export to Excel. Txt. Html. Xml csv in? 2011-05-11

    Select the result set, right click and select copy to excel can be exported to a temporary excel files, such as temp001.xls, and then choose File - Save As to save for our files. Select the result set, right click and select Export Results, select th

  • Export CSV file using Java reflection to export Excel alternative 2010-03-28

    package com.resoft.prophet.util; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter;

  • Import and export csv file (PL / SQL Developer) 2011-07-13

    In the use of database-related operations will always be dealing with import and export data. Therefore, data import and export of the familiar is very important, this will save a lot of time to our operations, do not have to spend too much time in t

  • With Java there is no good method to generate large amounts of data in Excel 2010-03-19

    The earliest Published time :2009-01-13 Online Excel file generated using the Java method, I am most popular POI project, but today from the afternoon until the evening of this part-time (around January 13, 2009 0:54:00) in the read data after numero

  • single table into sql server. Export 2011-04-21

    Method One, sql server single table import, export (via CSV file) Export: Open Query Analyzer directly query the information you want to export the table (select * from table), the result Select, Save as xxx.csv file (to get all the information in th

  • [6] MongoDB data import and export 2010-11-08

    MongoDB data import and export Requires prior created metadata. mongoimport This command can import a single JSON / CSV / TSV format. Each line of the file format should be the standard format specified. Need to specify a database (database) and a co

  • the efficiency of import and export excel 2011-05-27

    Recently by Microsoft:: Office:: Interop:: Excel to do import and export. Found extremely slow. Debugging found, api calls inside a function with remote indication. Accordingly I guess, this interface is similar to the ejb, but also crater father stu

  • Oracle database in the CSV Import method 2011-03-16

    In Plsql Developer in export to csv very convenient, but no corresponding reverse the import function, such as a particular query, the results do save the export to csv, then again if you need to import the csv file, database, query data in this part

  • 详解PHP导入导出CSV文件 2013-12-10

    项目开发中,很多时候要将外部CSV文件导入到数据库中或者将数据导出为CSV文件,那么具体该如何实现呢?本文将使用PHP并结合mysql,实现了CSV格式数据的导入和导出功能. 我们先准备mysql数据表,假设项目中有一张记录学生信息的表student,并有id,name,sex,age分别记录学生的姓名.性别.年龄等信息. CREATE TABLE `student` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT N

  • WordPress 后台添加数据库导入导出CSV功能 2014-05-30

    /*************************************************** * Application Actions * *************************************************/ function application_admin_pages() { add_menu_page(__('Application'), __('Application'), 'manage_options', basename(__FILE

  • 使用PHP导入和导出CSV文件(转)--好文章要共享! 2015-05-01

    我们先准备mysql数据表,假设项目中有一张记录学生信息的表student,并有id,name,sex,age分别记录学生的姓名.性别.年龄等信息. CREATE TABLE `student` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL, `sex` varchar(10) NOT NULL, `age` smallint(3) NOT NULL default '0', PRIMARY KEY (`i

  • ruby two ways to resolve the execl 2009-05-17

    If developed under the windows at you, you can use WIN32OLE The following is a sample procedure: require 'win23ole' application = WIN32OLE.new('Excel.Application') worksheet =application.Workbooks.Open(excelFileName).Worksheets(workSheetName) workshe

  • The essence of post finishing 2010-08-18

    The ranks of conversion: http://topic.csdn.net/u/20080614/17/22e73f33-f071-46dc-b9bf-321204b1656f.html?33238 (summary post) http://topic.csdn.net/u/20090912/14/25d2e1b2-f352-4713-8618-d3433ba27bef.html?99104 (classic post) Merge separate table: http:

  • Extreme Table use -> JSP page displays 2010-12-03

    eXtreme Table Description ================== eXtreme Table is ExtremeCompontents (http://extremecomponents.org) in a powerful and easy to configure, extend, customize the Table control, which include paging, sorting, filtering, export Excel, pdf and