fgetcsv() does not work well on PHP7 as in PHP5 on Windows

PHP5 (Windows 8)でUTF-8のCSVを読み取れたfgetcsv()が、PHP7 (Windows 10)では一部の文字に対して正しく読み取れない。
Linux上では問題ないみたい

Reference: http://blog-tmtsts.rhcloud.com/1014 . 対応方法は面倒くさいので試していない。

例:

PHP

<?php
setlocale(LC_ALL, 'ja_JP.UTF-8');

$file = "app1.csv";
$f = fopen($file, "r");
while (($data = fgetcsv($f)) !== FALSE) {
echo "* ";
foreach ($data as $dat) {
echo "$dat, ";
}
echo "\n";
}
fclose($f);
?>

CSV

"address","Address","戻る"
"back","Back","戻る"
"bill_sheet","Billsheet","請求書"
"business_form","Business form","事業形態"
"business_form_corporate","Corporate","法人"
"business_form_individual","Individual","個人"
"cancel_project",,"ボツ案件"
"cannot_delete_invoiced_project",,"請求書が作成されたため、案件は削除できません。"

Output

* address, Address, 戻る"
back", Back, 戻る"
bill_sheet", Billsheet, 請求書,
* business_form, Business form, 事業形態"
business_form_corporate", Corporate, 法人,
* business_form_individual, Individual, 個人,
* cancel_project, , ボツ案件,
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: