Changeset 15532 for branches/feature-module-update/convert.php
- Timestamp:
- 2007/08/31 23:39:46 (17 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=EUC-JP to text/x-httpd-php; charset=UTF-8
r15081 r15532 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.