0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHP csvファイルを Shift-JIS => UTF-8 へ変換

Posted at

■ 完成

・ファイル名:Change_Character_code.php
スクリーンショット (692).png

スクリーンショット (691).png

■ ソースコード

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);
  }
}


?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?