source: branches/comu/convert.php @ 11974

Revision 11974, 1.8 KB checked in by nanasess, 17 years ago (diff)

$includes に .sql 追加

  • Property svn:executable set to *
  • Property svn:keywords set to HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Line 
1#!/usr/local/bin/php
2<?php
3/**
4 * ¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò $fromEncoding ¤«¤é $toEncoding ¤ØÊÑ´¹¤·¤Þ¤¹.
5 *
6 * @version $Revision$ $Date$
7 * @author  Kentaro Ohkouchi
8 */
9
10/** include files suffix. */
11$includes = ".php,.inc,.tpl,.css,.sql";
12
13/** convert from encoding. */
14$fromEncoding = "EUC-JP";
15/** convert to encoding. */
16$toEncoding = "UTF-8";
17
18$includeArray = explode(',', $includes);
19$fileArrays = listdirs('.');
20
21foreach ($fileArrays as $path) {
22    if (is_file($path)) {
23        $fileName = basename($path);
24        $suffix = substr($fileName, -4);
25
26        foreach ($includeArray as $include) {
27            if ($suffix == $include) {
28                $contents = file_get_contents($path);
29                $convertedContents = mb_convert_encoding($contents,
30                                                         $toEncoding,
31                                                         $fromEncoding);
32
33                if (is_writable($path)) {
34
35                    // file open
36                    $handle = fopen($path, "w");
37                    if (!$handle) {
38                        echo "Cannot open file (". $path . ")";
39                        continue;
40                    }
41
42                    if (fwrite($handle, $convertedContents) === false) {
43                        echo "Cannot write to file (" . $path . ")";
44                        continue;
45                    }
46
47                    echo "converted " . $path . "\n";
48                    fclose($handle);
49                } else {
50
51                    echo "The file " . $filename . "is not writable";
52                }
53            }
54        }
55    }
56}
57
58function listdirs($dir) {
59    static $alldirs = array();
60    $dirs = glob($dir . '/*');
61    if (count($dirs) > 0) {
62        foreach ($dirs as $d) $alldirs[] = $d;
63    }
64    foreach ($dirs as $dir) listdirs($dir);
65    return $alldirs;
66}
67?>
68
Note: See TracBrowser for help on using the repository browser.