Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

to-utf8.php

汎用 CP932(Shift_JIS-win) / EUC-JP → UTF-8 変換ツール。単一ファイル・ディレクトリ再帰走査の両方に対応。 mbstring不在の環境でも動作するよう、変換元エンコーディングの自動判定は独自のバイトパターン ヒューリスティックで行い、実際の変換はiconv()で行う。

使い方

php to-utf8.php <path> [options]

<path> がファイルなら単一ファイル変換、ディレクトリなら指定拡張子のファイルを再帰的に変換する。

オプション

オプション 説明
--from=AUTO|CP932|EUCJP 変換元エンコーディング(省略時はAUTO=自動判定)
--ext=php,pl,cgi,... 対象拡張子(ディレクトリ指定時のみ有効、カンマ区切り)
--out-dir=DIR 出力先ディレクトリ(省略時は ./utf8_out/
--out=FILE 出力先ファイル(単一ファイル変換時のみ、--out-dirより優先)
--recursive サブディレクトリも走査する
--dry-run 実際には書き込まず、変換対象と判定結果のみ表示
-h, --help ヘルプを表示

# ディレクトリ配下のphp/txtファイルをまとめて変換
php to-utf8.php ./legacy --ext=php,txt --out-dir=./converted

# 単一ファイルを指定した出力先へ
php to-utf8.php old.txt --from=CP932 --out=new.txt

方針

  • 元ファイルは常に無改変。変換結果は別ファイルへ出力する。
  • 既にUTF-8として妥当なファイルは変換せずそのままコピーする。

ライセンス

MIT License(LICENSE参照)

ドキュメント

開発経緯は doc/changelog.md を参照。

About

汎用CP932(Shift_JIS-win)/EUC-JP→UTF-8変換ツール。単一ファイル・ディレクトリ再帰走査の両対応、自動判定/明示指定両対応、元ファイル無改変。/ Generic CP932(Shift_JIS-win)/EUC-JP to UTF-8 converter for PHP. Supports single files and recursive directories, auto or explicit encoding detection, never modifies the source file.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages