制作网站时,经常会遇到检索数据列表的情况。通常用户希望下载这些列表数据并存储到客户端。当然下载这些数据的时候是需要固定的格式,以便于用Excel等软件阅览。说的简单一些就是CSV/Excel数据导出 。
注意事项:
输出文档的基本格式为:列1,列2,列3,……,列nn
格式化数据的同时要对特殊的字符进行过滤。譬如“,”如果不转换为全角“,”会导致数据格式的混乱。
实现方法:
举例:检索数据库表,将结果保存为字符串,进行格式和特殊字符的过滤后,导出到客户端的CSV文件。
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();// 调用doCSV()方法
$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 "注文No.,注文日,氏名,住所,支

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment