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