Create a gist now

Instantly share code, notes, and snippets.

@bz0 /composer.json
Last active Feb 11, 2017

csvのローカルダウンロード(JIS第3・第4水準の文字化け対策・Volcanus_Csvライブラリを利用)
{
"require": {
"volcanus/csv": "^1.1"
}
}
<?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