PHP Export csv method (RPM)

Source: Internet
Author: User

When you make a Web site, you often experience retrieving lists of data. Typically, users want to download these list data and store them to the client. Of course, when downloading this data, you need a fixed format, so that you can use Excel and other software to read. The simple thing to say is csv/excel data export.

Precautions:

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

When you format the data, you filter the special characters. For example, "If you do not convert to full angle," can cause confusion in the data format.

Implementation method:

Example: Retrieves a database table, saves the result as a string, formats and filters the special characters, and exports it to the client's CSV file.

ordersearchedit_savecsv.php



? 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 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   " Annotations No., annotations day, name, residence, 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.