Php export CSV method)-PHP source code

Source: Internet
Author: User
Ec (2); & nbsp; when creating a website, you may frequently retrieve data lists. Users usually want to download the list data and store it on the client. Of course, a fixed format is required for downloading the data so that it can be viewed in Excel or other software. To put it simply, export data from CSVExcel. Note: the basic format of the output document is column 1, column 2, column 3, & hellip;. When formatting data with column nn, you must filter out special characters. For example, & ldquo script ec (2); script

When you create a website, you may frequently retrieve data lists. Users usually want to download the list data and store it on the client. Of course, a fixed format is required for downloading the data so that it can be viewed in Excel or other software. To put it simply, export CSV/Excel Data.

Note:

The basic format of the output document is: column 1, column 2, column 3 ,......, Column nn

When formatting data, you must filter out special characters. For example, if "," is not converted to full-width "," it will lead to confusion in the data format.

Implementation Method:

For example, you can search the database table, save the result as a string, filter the format and special characters, and export the result to the CSV file on the client.

OrderSearchEdit_saveCSV.php



Include ($ _ SERVER [''document _ root'']. "/ftcart/OrderInfoManager. class. php ");
Include ($ _ SERVER [''document _ root'']. "/ftcart/CommonUtil. php ");
Include ($ _ SERVER [''document _ root'']. "/ftcart/CommonConst. php ");
Include ($ _ SERVER [''document _ root'']. "/ftcart/CommonErrorMsg. php ");
Include ($ _ SERVER [''document _ root'']. "/webadmin. php ");

$ Searchcase = new OrderInfoManager ();
$ NowTime = microtime_float ();
$ Searchcase = unserialize ($ _ SESSION ["ORDER_SEARCH_CASE"]);
$ Listcsv = $ searchcase-> doCSV (); // call the doCSV () method
$ Filename = $ nowTime;
// $ Filename = str_replace (":", "", $ nowTime );
// $ Filename = trim ($ filename );
// Echo $ filename;
Header ("Content-Disposition: attachment; filename =". $ filename. ". csv ");
Header (''content-Type: APPLICATION/OCTET-STREAM '');
Echo "Note No., note day, name, domicile, Branch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.