Ignore:
Timestamp:
2007/04/01 08:51:24 (17 years ago)
Author:
nanasess
Message:

除外ファイル名を指定できるよう変更.
変換ファイル拡張子の指定方法を変更.
コメントを追加し, リファクタリング.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu/convert.php

    r11974 r12040  
    44 * ¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò $fromEncoding ¤«¤é $toEncoding ¤ØÊÑ´¹¤·¤Þ¤¹. 
    55 * 
    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$ 
    89 */ 
    910 
    10 /** include files suffix. */ 
    11 $includes = ".php,.inc,.tpl,.css,.sql"; 
     11/** 
     12 * ÊÑ´¹¤·¤¿¤¤¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó. 
     13 */ 
     14$includes = "php,inc,tpl,css,sql,js"; 
    1215 
    13 /** convert from encoding. */ 
     16/** 
     17 * ½ü³°¤¹¤ë¥Õ¥¡¥¤¥ë̾¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó. 
     18 */ 
     19$excludes = "convert.php"; 
     20 
     21/** 
     22 * ÊÑ´¹¸µ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°. 
     23 */ 
    1424$fromEncoding = "EUC-JP"; 
    15 /** convert to encoding. */ 
     25 
     26/** 
     27 * ÊÑ´¹À襨¥ó¥³¡¼¥Ç¥£¥ó¥°. 
     28 */ 
    1629$toEncoding = "UTF-8"; 
    1730 
    1831$includeArray = explode(',', $includes); 
     32$excludeArray = explode(',', $excludes); 
    1933$fileArrays = listdirs('.'); 
    2034 
    2135foreach ($fileArrays as $path) { 
    2236    if (is_file($path)) { 
    23         $fileName = basename($path); 
    24         $suffix = substr($fileName, -4); 
    2537 
     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        // ÊÑ´¹Âоݤò½ç¤Ë½èÍý 
    2651        foreach ($includeArray as $include) { 
    2752            if ($suffix == $include) { 
     53                 
     54                // ¥Õ¥¡¥¤¥ëÆâÍƤò¼èÆÀ¤·, ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÊÑ´¹ 
    2855                $contents = file_get_contents($path); 
    2956                $convertedContents = mb_convert_encoding($contents, 
     
    3158                                                         $fromEncoding); 
    3259 
     60                // ½ñ¤­¹þ¤ß¤Ç¤­¤ë¤«¡© 
    3361                if (is_writable($path)) { 
    3462 
    35                     // file open 
     63                    // ¥Õ¥¡¥¤¥ë¤ò½ñ¤­½Ð¤·¥â¡¼¥É¤Ç³«¤¯ 
    3664                    $handle = fopen($path, "w"); 
    3765                    if (!$handle) { 
     
    4068                    } 
    4169 
     70                    // ¥³¡¼¥ÉÊÑ´¹¤·¤¿ÆâÍƤò½ñ¤­¹þ¤à  
    4271                    if (fwrite($handle, $convertedContents) === false) { 
    4372                        echo "Cannot write to file (" . $path . ")"; 
     
    4675 
    4776                    echo "converted " . $path . "\n"; 
     77                    // ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë 
    4878                    fclose($handle); 
    4979                } else { 
     
    5686} 
    5787 
     88/** 
     89 * $dir ¤òºÆµ¢Åª¤Ëé¤Ã¤Æ¥Ñ¥¹Ì¾¤òÇÛÎó¤ÇÊÖ¤¹. 
     90 *  
     91 * @param string Ǥ°Õ¤Î¥Ñ¥¹Ì¾ 
     92 * @return array $dir ¤è¤ê²¼Áؤ˸ºß¤¹¤ë¥Ñ¥¹Ì¾¤ÎÇÛÎó 
     93 * @see http://www.php.net/glob 
     94 */ 
    5895function listdirs($dir) { 
    5996    static $alldirs = array(); 
     
    66103} 
    67104?> 
    68  
Note: See TracChangeset for help on using the changeset viewer.