Definition and usage
The header () function sends the original HTTP header to the client.
It is important to recognize that the header () function must be called before any actual output is sent (in PHP 4 and later, you can use output caching to resolve this issue):
Result error
Output already exists before the header () is called
Header (' location:http://www.zhutiai.com/');
?> syntax
Header (string,replace,http_response_code) parameter description
string is required. Specifies the string of headers to send.
Replace is optional. Indicates whether the header replaces the previous header, or adds a second header.
The default is true (replace). False (multiple headers of the same type are allowed).
Http_response_code is optional. Forces the HTTP response code to the specified value. (Available in PHP 4 and later)
1. Define headers () header output format
Header ("Content-type:application/vnd.ms-excel"); Define the file type of the output
Header ("Content-disposition:filename=downloaded.pdf"); Define the file name of the output, that is, set a download type, when downloading the file from the new name
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=downloaded.pdf");
echo "1t 2t 3n"; where t is blank, n is carriage return (encoding specification cannot be output directly)
echo "1t 2t 3n";
echo "1t 2t 3n";
?>
This time you can open this PHP file, you will be prompted to download.
can also be output in table table;
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=downloaded.pdf");
?>
t00 |
t01 |
t02 |
T10 |
T11 |
T12 |
T20 |
T21 |
T22 |
Write Operations for CSV:
Fputcsv () can be used for reference.
$fp = fopen (' f:/file.csv ', ' W ');
Fputcsv ($fp, Array (' AAA ', ' BBB ', ' CCCC '));
Fputcsv ($fp, Array (' mmm ', ' yyy ', ' haha ')); Fputcsv () can be implemented in the form of an array loop
Fclose ($FP);
http://www.bkjia.com/PHPjc/630751.html www.bkjia.com true http://www.bkjia.com/PHPjc/630751.html techarticle define and use the header () function to send the original HTTP header to the client. It is important to recognize that the header () function must be called before any actual output is sent (in PH ...