Home  >  Article  >  php教程  >  php output, write to csv

php output, write to csv

WBOY
WBOYOriginal
2016-07-09 09:09:341416browse

1. First, we will use the usage of header() in php

Here you can refer to the PHP header() function in w3school and php Use to use header function to number ’s httpheadsetset .

The header() function is called before any actual output is sent.

The following is an example of using php to output csv.

1. Define the header() header output format

header("Content-type:application/vnd.ms-excel"); //Define the output File type

header(“content-Disposition:filename=downloaded.pdf”); //Define the output file name, that is, set a download type, and rename the file when downloading

php
header(" Content-type:application/vnd.ms-excel");
header(" content-Disposition:filename=downloaded.pdf ");

echo" 1t 2t 3n"; //where t is blank and n is carriage return (encoding specifications cannot Direct output)
echo"1t 2t 3n";
echo"1t 2t 3n";


?>

You can open the php file at this time and you will be prompted to download it.

can also be output in the form of a table;


php
header("Content-type:application/vnd.ms-excel ");
header("content-Disposition:filename=downloaded.pdf");
?>
 tr>
 td >
t00
td>td>t01td>td>t02td> tr>
 
tr>
 td>
t10
td>td>t11td>td> t12td> tr>
 
tr>
 td>
t20
td>td>t21td> td>t22td> tr>
table>

CSV writing operation:

For the usage of fputcsv(), please refer to.

$fp = fopen('f:/file.csv', 'w');
fputcsv(
$fp,array(' aaa','bbb','cccc'));
fputcsv(
$fp,array('mmm','yyy','haha')); 🎜>//fputcsv() can be implemented using an array loop
$fp);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn