Created
February 20, 2012 06:01
-
-
Save tanakahisateru/1868071 to your computer and use it in GitHub Desktop.
CSV via HTTP response by PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
header('Content-Type: text/plain;charset=UTF-8'); | |
$stream = fopen('php://output', 'w'); | |
fputcsv($stream, array(1, 2, 3)); | |
fputcsv($stream, array(4, 5, 6)); | |
// more complex codes would be here. It may cause error. | |
header("Content-Type: application/octet-stream"); | |
header("Content-Disposition: attachment; filename=output.csv"); | |
echo mb_convert_encoding(ob_get_clean(), 'SJIS', 'UTF-8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment