Changeset 15081 for branches/feature-module-update/convert.php
- Timestamp:
- 2007/07/20 16:42:55 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/convert.php
- Property svn:mime-type changed from application/x-httpd-php; charset=UTF-8 to application/x-httpd-php; charset=EUC-JP
r15080 r15081 2 2 <?php 3 3 /** 4 * ¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò $fromEncoding ¤«¤é $toEncoding ¤ØÊÑ´¹¤·¤Þ¤¹.4 * ファイルのエンコーディングを $fromEncoding から $toEncoding へ変換します. 5 5 * 6 6 * @author Kentaro Ohkouchi<ohkouchi@loop-az.jp> … … 10 10 11 11 /** 12 * ÊÑ´¹¤·¤¿¤¤¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó.12 * 変換したいファイルの拡張子をカンマ区切りで羅列. 13 13 */ 14 14 $includes = "php,inc,tpl,css,sql,js"; 15 15 16 16 /** 17 * ½ü³°¤¹¤ë¥Õ¥¡¥¤¥ë̾¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó.17 * 除外するファイル名をカンマ区切りで羅列. 18 18 */ 19 19 $excludes = "convert.php"; 20 20 21 21 /** 22 * ÊÑ´¹¸µ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°.22 * 変換元エンコーディング. 23 23 */ 24 24 $fromEncoding = "EUC-JP"; 25 25 26 26 /** 27 * ÊÑ´¹À襨¥ó¥³¡¼¥Ç¥£¥ó¥°.27 * 変換先エンコーディング. 28 28 */ 29 29 $toEncoding = "UTF-8"; … … 36 36 if (is_file($path)) { 37 37 38 // ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ38 // ファイル名を取得 39 39 $fileName = pathinfo($path, PATHINFO_BASENAME); 40 40 41 // ³ÈÄ¥»Ò¤ò¼èÆÀ41 // 拡張子を取得 42 42 $suffix = pathinfo($path, PATHINFO_EXTENSION); 43 43 44 // ½ü³°¥Õ¥¡¥¤¥ë¤ò¥¹¥¥Ã¥×44 // 除外ファイルをスキップ 45 45 if (in_array($fileName, $excludeArray)) { 46 46 echo "excludes by " . $path . "\n"; … … 48 48 } 49 49 50 // ÊÑ´¹Âоݤò½ç¤Ë½èÍý50 // 変換対象を順に処理 51 51 foreach ($includeArray as $include) { 52 52 if ($suffix == $include) { 53 53 54 // ¥Õ¥¡¥¤¥ëÆâÍÆ¤ò¼èÆÀ¤·, ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÊÑ´¹54 // ファイル内容を取得し, エンコーディング変換 55 55 $contents = file_get_contents($path); 56 56 $convertedContents = mb_convert_encoding($contents, … … 58 58 $fromEncoding); 59 59 60 // ½ñ¤¹þ¤ß¤Ç¤¤ë¤«¡©60 // 書き込みできるか? 61 61 if (is_writable($path)) { 62 62 63 // ¥Õ¥¡¥¤¥ë¤ò½ñ¤½Ð¤·¥â¡¼¥É¤Ç³«¤¯63 // ファイルを書き出しモードで開く 64 64 $handle = fopen($path, "w"); 65 65 if (!$handle) { … … 68 68 } 69 69 70 // ¥³¡¼¥ÉÊÑ´¹¤·¤¿ÆâÍÆ¤ò½ñ¤¹þ¤à70 // コード変換した内容を書き込む 71 71 if (fwrite($handle, $convertedContents) === false) { 72 72 echo "Cannot write to file (" . $path . ")"; … … 75 75 76 76 echo "converted " . $path . "\n"; 77 // ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë77 // ファイルを閉じる 78 78 fclose($handle); 79 79 } else { … … 87 87 88 88 /** 89 * $dir ¤òºÆµ¢Åª¤Ëé¤Ã¤Æ¥Ñ¥¹Ì¾¤òÇÛÎó¤ÇÊÖ¤¹.89 * $dir を再帰的に辿ってパス名を配列で返す. 90 90 * 91 * @param string Ǥ°Õ¤Î¥Ñ¥¹Ì¾92 * @return array $dir ¤è¤ê²¼Áؤ˸ºß¤¹¤ë¥Ñ¥¹Ì¾¤ÎÇÛÎó91 * @param string 任意のパス名 92 * @return array $dir より下層に存在するパス名の配列 93 93 * @see http://www.php.net/glob 94 94 */
Note: See TracChangeset
for help on using the changeset viewer.