Changeset 15603 for branches


Ignore:
Timestamp:
2007/09/05 10:45:00 (17 years ago)
Author:
nanasess
Message:

エンコーディングを UTF-8 に変更

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/convert.php

    r15532 r15603  
    11#!/usr/local/bin/php 
    22<?php 
     3/* 
     4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. 
     5 * 
     6 * http://www.lockon.co.jp/ 
     7 */ 
     8 
    39/** 
    4  * ¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò $fromEncoding ¤«¤é $toEncoding ¤ØÊÑ´¹¤·¤Þ¤¹. 
     10 * ファイルのエンコーディングを $fromEncoding から $toEncoding へ変換します. 
    511 * 
    612 * @author  Kentaro Ohkouchi<ohkouchi@loop-az.jp> 
     
    1016 
    1117/** 
    12  * ÊÑ´¹¤·¤¿¤¤¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó. 
     18 * 変換したいファイルの拡張子をカンマ区切りで羅列. 
    1319 */ 
    1420$includes = "php,inc,tpl,css,sql,js"; 
    1521 
    1622/** 
    17  * ½ü³°¤¹¤ë¥Õ¥¡¥¤¥ë̾¤ò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÍåÎó. 
     23 * 除外するファイル名をカンマ区切りで羅列. 
    1824 */ 
    1925$excludes = "convert.php"; 
    2026 
    2127/** 
    22  * ÊÑ´¹¸µ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°. 
     28 * 変換元エンコーディング. 
    2329 */ 
    2430$fromEncoding = "EUC-JP"; 
    2531 
    2632/** 
    27  * ÊÑ´¹À襨¥ó¥³¡¼¥Ç¥£¥ó¥°. 
     33 * 変換先エンコーディング. 
    2834 */ 
    2935$toEncoding = "UTF-8"; 
     
    3642    if (is_file($path)) { 
    3743 
    38         // ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ 
     44        // ファイル名を取得 
    3945        $fileName = pathinfo($path, PATHINFO_BASENAME); 
    40          
    41         // ³ÈÄ¥»Ò¤ò¼èÆÀ 
     46 
     47        // 拡張子を取得 
    4248        $suffix = pathinfo($path, PATHINFO_EXTENSION); 
    4349 
    44         // ½ü³°¥Õ¥¡¥¤¥ë¤ò¥¹¥­¥Ã¥× 
     50        // 除外ファイルをスキップ 
    4551        if (in_array($fileName, $excludeArray)) { 
    4652            echo "excludes by " . $path . "\n"; 
     
    4854        } 
    4955 
    50         // ÊÑ´¹Âоݤò½ç¤Ë½èÍý 
     56        // 変換対象を順に処理 
    5157        foreach ($includeArray as $include) { 
    5258            if ($suffix == $include) { 
    53                  
    54                 // ¥Õ¥¡¥¤¥ëÆâÍƤò¼èÆÀ¤·, ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÊÑ´¹ 
     59 
     60                // ファイル内容を取得し, エンコーディング変換 
    5561                $contents = file_get_contents($path); 
    5662                $convertedContents = mb_convert_encoding($contents, 
     
    5864                                                         $fromEncoding); 
    5965 
    60                 // ½ñ¤­¹þ¤ß¤Ç¤­¤ë¤«¡© 
     66                // 書き込みできるか? 
    6167                if (is_writable($path)) { 
    6268 
    63                     // ¥Õ¥¡¥¤¥ë¤ò½ñ¤­½Ð¤·¥â¡¼¥É¤Ç³«¤¯ 
     69                    // ファイルを書き出しモードで開く 
    6470                    $handle = fopen($path, "w"); 
    6571                    if (!$handle) { 
     
    6874                    } 
    6975 
    70                     // ¥³¡¼¥ÉÊÑ´¹¤·¤¿ÆâÍƤò½ñ¤­¹þ¤à  
     76                    // コード変換した内容を書き込む 
    7177                    if (fwrite($handle, $convertedContents) === false) { 
    7278                        echo "Cannot write to file (" . $path . ")"; 
     
    7581 
    7682                    echo "converted " . $path . "\n"; 
    77                     // ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë 
     83                    // ファイルを閉じる 
    7884                    fclose($handle); 
    7985                } else { 
     
    8793 
    8894/** 
    89  * $dir ¤òºÆµ¢Åª¤Ëé¤Ã¤Æ¥Ñ¥¹Ì¾¤òÇÛÎó¤ÇÊÖ¤¹. 
    90  *  
    91  * @param string Ǥ°Õ¤Î¥Ñ¥¹Ì¾ 
    92  * @return array $dir ¤è¤ê²¼Áؤ˸ºß¤¹¤ë¥Ñ¥¹Ì¾¤ÎÇÛÎó 
     95 * $dir を再帰的に辿ってパス名を配列で返す. 
     96 * 
     97 * @param string 任意のパス名 
     98 * @return array $dir より下層に存在するパス名の配列 
    9399 * @see http://www.php.net/glob 
    94100 */ 
Note: See TracChangeset for help on using the changeset viewer.