Changeset 12040 for branches/comu/convert.php
- Timestamp:
- 2007/04/01 08:51:24 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/comu/convert.php
r11974 r12040 4 4 * ¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò $fromEncoding ¤«¤é $toEncoding ¤ØÊÑ´¹¤·¤Þ¤¹. 5 5 * 6 * @version $Revision$ $Date$ 7 * @author Kentaro Ohkouchi 6 * @author Kentaro Ohkouchi<ohkouchi@loop-az.jp> 7 * @since PHP4.3.0(cli) 8 * @version $Id$ 8 9 */ 9 10 10 /** include files suffix. */ 11 $includes = ".php,.inc,.tpl,.css,.sql"; 11 /** 12 * ÊÑ´¹¤·¤¿¤¤¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó. 13 */ 14 $includes = "php,inc,tpl,css,sql,js"; 12 15 13 /** convert from encoding. */ 16 /** 17 * ½ü³°¤¹¤ë¥Õ¥¡¥¤¥ë̾¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó. 18 */ 19 $excludes = "convert.php"; 20 21 /** 22 * ÊÑ´¹¸µ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°. 23 */ 14 24 $fromEncoding = "EUC-JP"; 15 /** convert to encoding. */ 25 26 /** 27 * ÊÑ´¹À襨¥ó¥³¡¼¥Ç¥£¥ó¥°. 28 */ 16 29 $toEncoding = "UTF-8"; 17 30 18 31 $includeArray = explode(',', $includes); 32 $excludeArray = explode(',', $excludes); 19 33 $fileArrays = listdirs('.'); 20 34 21 35 foreach ($fileArrays as $path) { 22 36 if (is_file($path)) { 23 $fileName = basename($path);24 $suffix = substr($fileName, -4);25 37 38 // ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ 39 $fileName = pathinfo($path, PATHINFO_BASENAME); 40 41 // ³ÈÄ¥»Ò¤ò¼èÆÀ 42 $suffix = pathinfo($path, PATHINFO_EXTENSION); 43 44 // ½ü³°¥Õ¥¡¥¤¥ë¤ò¥¹¥¥Ã¥× 45 if (in_array($fileName, $excludeArray)) { 46 echo "excludes by " . $path . "\n"; 47 continue; 48 } 49 50 // ÊÑ´¹Âоݤò½ç¤Ë½èÍý 26 51 foreach ($includeArray as $include) { 27 52 if ($suffix == $include) { 53 54 // ¥Õ¥¡¥¤¥ëÆâÍÆ¤ò¼èÆÀ¤·, ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÊÑ´¹ 28 55 $contents = file_get_contents($path); 29 56 $convertedContents = mb_convert_encoding($contents, … … 31 58 $fromEncoding); 32 59 60 // ½ñ¤¹þ¤ß¤Ç¤¤ë¤«¡© 33 61 if (is_writable($path)) { 34 62 35 // file open63 // ¥Õ¥¡¥¤¥ë¤ò½ñ¤½Ð¤·¥â¡¼¥É¤Ç³«¤¯ 36 64 $handle = fopen($path, "w"); 37 65 if (!$handle) { … … 40 68 } 41 69 70 // ¥³¡¼¥ÉÊÑ´¹¤·¤¿ÆâÍÆ¤ò½ñ¤¹þ¤à 42 71 if (fwrite($handle, $convertedContents) === false) { 43 72 echo "Cannot write to file (" . $path . ")"; … … 46 75 47 76 echo "converted " . $path . "\n"; 77 // ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë 48 78 fclose($handle); 49 79 } else { … … 56 86 } 57 87 88 /** 89 * $dir ¤òºÆµ¢Åª¤Ëé¤Ã¤Æ¥Ñ¥¹Ì¾¤òÇÛÎó¤ÇÊÖ¤¹. 90 * 91 * @param string Ǥ°Õ¤Î¥Ñ¥¹Ì¾ 92 * @return array $dir ¤è¤ê²¼Áؤ˸ºß¤¹¤ë¥Ñ¥¹Ì¾¤ÎÇÛÎó 93 * @see http://www.php.net/glob 94 */ 58 95 function listdirs($dir) { 59 96 static $alldirs = array(); … … 66 103 } 67 104 ?> 68
Note: See TracChangeset
for help on using the changeset viewer.