PHP output and write CSV

Source: Internet
Author: User
Tags php source code

Introduction: This is a detailed page for PHP output and CSV writing. It introduces the related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 337308 'rolling = 'no'>

1. First, use the header () in PHP.

For more information, see the PHP header () function and P in w3school.HPMediumEnableUseHEADERLetterQuantityOfHTTPHeaderSetSet.

The Header () function must be called before any actual output is sent.

Below is a CSV sample output in PHP.

 

1. Define the header output format

Header ("Content-Type: Application/vnd. MS-excel"); // defines the output file type

Header ("Content-Disposition: filename =downloaded.pdf"); // Define the output file name, that is, set a download type. The file is renamed during download.

 

<? PHP
Header ("Content-Type: Application/vnd. MS-excel ");
Header ("content-Disposition: filenameappsdownloaded.pdf ");

Echo "1 \ t 2 \ t 3 \ n"; // where \ t is blank and \ n is carriage return (encoding specifications cannot be output directly)
Echo "1 \ t 2 \ t 3 \ n ";
Echo "1 \ t 2 \ t 3 \ n ";

?>

 

In this case, you can open the PHP file and a prompt will be displayed for download.

 

It can also be output as a table;

<? PHP
Header ("Content-Type: Application/vnd. MS-excel ");
Header ("content-Disposition: filenameappsdownloaded.pdf ");
?>
<Table>
<Tr>
<TD> t00 </TD> <TD> t01 </TD> <TD> t02 </TD>
</Tr>
<Tr>
<TD> T10 </TD> <TD> T11 </TD> <TD> T12 </TD>
</Tr>
<Tr>
<TD> T20 </TD> <TD> T21 </TD> <TD> T22 </TD>
</Tr>
</Table>

 

CSV write operation:

For use of fputcsv (), refer.

 

$ Fp = fopen ('f:/file.csv ', 'w ');
Fputcsv ($ FP, array ('aaa', 'bbb ', 'cccccc '));
Fputcsv ($ FP, array ('mmm', 'yyy', 'hahaha'); // fputcsv () can be implemented using array loops.
Fclose ($ FP );

 

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/337308.html pageno: 9.

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.