■ 完成
・ファイル名:Change_Character_code.php
■ ソースコード
php Change_Character_code.php
<?php
// フォルダのパスを指定
$folder_path = "./";
// フォルダ内のファイルを取得
$files = scandir($folder_path);
var_dump($files);
foreach ($files as $file_val) {
// ファイル名が".csv"で終わるかどうかを確認
if (substr($file_val, -4) == '.csv') {
// ファイルを開く
$content = file_get_contents($folder_path . $file_val);
// Shift-JISからUTF-8に変換
$content = mb_convert_encoding($content, 'UTF-8', 'Shift-JIS');
// ファイルを保存
file_put_contents($folder_path . $file_val, $content);
}
}
?>