Changeset 17492
- Timestamp:
- 2008/08/05 17:13:20 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2/data/class/util/SC_Utils.php
r17398 r17492 1022 1022 } 1023 1023 1024 /** 1025 * テキストファイルの文字エンコーディングを変換する. 1026 * 1027 * $filepath に存在するテキストファイルの文字エンコーディングを変換する. 1028 * 変換前の文字エンコーディングは, mb_detect_order で設定した順序で自動検出する. 1029 * 変換後は, 変換前のファイル名に「enc_」というプレフィクスを付与し, 1030 * $out_dir で指定したディレクトリへ出力する 1031 * 1032 * TODO $filepath のファイルがバイナリだった場合の扱い 1033 * TODO fwrite などでのエラーハンドリング 1034 * 1035 * @access public 1036 * @param string $filepath 変換するテキストファイルのパス 1037 * @param string $enc_type 変換後のファイルエンコーディングの種類を表す文字列 1038 * @param string $out_dir 変換後のファイルを出力するディレクトリを表す文字列 1039 * @return string 変換後のテキストファイルのパス 1040 */ 1024 1041 function sfEncodeFile($filepath, $enc_type, $out_dir) { 1025 1042 $ifp = fopen($filepath, "r"); 1026 1043 1027 $basename = basename($filepath); 1028 $outpath = $out_dir . "enc_" . $basename; 1029 1030 $ofp = fopen($outpath, "w+"); 1031 1032 while(!feof($ifp)) { 1033 $line = fgets($ifp); 1034 $line = mb_convert_encoding($line, $enc_type, "auto"); 1035 fwrite($ofp, $line); 1036 } 1037 1038 fclose($ofp); 1039 fclose($ifp); 1040 1044 // 正常にファイルオープンした場合 1045 if ($ifp !== false) { 1046 1047 $basename = basename($filepath); 1048 $outpath = $out_dir . "enc_" . $basename; 1049 1050 $ofp = fopen($outpath, "w+"); 1051 1052 while(!feof($ifp)) { 1053 $line = fgets($ifp); 1054 $line = mb_convert_encoding($line, $enc_type, "auto"); 1055 fwrite($ofp, $line); 1056 } 1057 1058 fclose($ofp); 1059 fclose($ifp); 1060 } 1061 // ファイルが開けなかった場合はエラーページを表示 1062 else { 1063 SC_Utils::sfDispError(''); 1064 exit; 1065 } 1041 1066 return $outpath; 1042 1067 }
Note: See TracChangeset
for help on using the changeset viewer.