Last active
February 11, 2017 02:52
-
-
Save bz0/23b33d0c0d6b8e11e92805850eedf186 to your computer and use it in GitHub Desktop.
csvのローカルダウンロード(JIS第3・第4水準の文字化け対策・Volcanus_Csvライブラリを利用)
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
{ | |
"require": { | |
"volcanus/csv": "^1.1" | |
} | |
} |
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 | |
//https://github.com/k-holy/Volcanus_Csv/blob/master/README.md | |
require_once 'vendor/autoload.php'; | |
$file = new \SplFileObject('php://temp', 'r+'); | |
$writer = new \Volcanus\Csv\Writer(array( | |
'writeHeaderLine' => true, | |
'responseFilename' => 'users.csv', | |
)); | |
$writer->fields(array( | |
array('id' , 'ID'), | |
array('string' , '文字列'), | |
)); | |
$data = array( | |
array( | |
'id' => "1", | |
'string' => "JIS第3水準 俱𠀋㐂丨丯丰亍仡份" | |
), | |
array( | |
'id' => "2", | |
'string' => "JIS第4水準 𠂉丂丏丒丩丫丮乀乇" | |
), | |
array( | |
'id' => "3", | |
'string' => "記号 ㈱ ㏍〃 仝 ゝ ゞ 々 〆 ヾ ― ‐ / 〇 ヽ _  ̄ ¨ ` ´ ゜ ゛ \ § ^ ≫ ¬ ⇒ ⇔ ∀ ∃ ∠ ⊥ ⌒ ∂ ∇ ≡ ∨ ≪ † √ ∽ ∝ ∵ ∫ ∬ Å ‰ ♯ ♭ ♪ ‡ ~ ′ ≒ × ∥ ∧ | … ± ÷ ≠ ≦ ≧ ∞ ∴ ♂ ♀ ∪ ‥ ° ⊃ ⊂ ⊇ ∩ ⊆ ∋ ∈ 〓 〒 ※ ″" | |
), | |
array( | |
'id' => "4", | |
'string' => "IBM拡張文字 ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ¬¦'"㈱№℡∵纊褜鍈銈" | |
), | |
array( | |
'id' => "5", | |
'string' => "NEC選定IBM拡張文字 纊褜鍈銈蓜俉炻昱棈鋹曻彅丨仡仼伀伃伹佖侒侊侚侔俍偀倢俿倞偆偰偂傔" | |
), | |
array( | |
'id' => "6", | |
'string' => "機種依存文字 ①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ㍉㌔" | |
), | |
); | |
$writer->file = $file; | |
//BOM | |
$BOM = pack('C*',0xEF,0xBB,0xBF); | |
$file->fwrite($BOM); | |
$writer->write($data); | |
// レスポンスヘッダとCSVを出力 | |
$writer->send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment