CLIでmbstringがつかえない

Twitter ツイート Hatena Bookmark ブックマーク

文字コードがSJISのファイルがたくさんあったので、PHPでさっくりと文字コードを変更してました。
しかしコードを実行してみるとなぜかエラーに。。。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function convertCtpEncode( $dir,$to_encoding = 'UTF-8',$from_enconding = 'SJIS' ) {

        $handle = opendir($dir);
        if (!$handle) {
            return ;
        }

        while (false !== ($item = readdir($handle))) {
            if ($item === "." || $item === "..") {
                continue;
            }

            $path = $dir . DIRECTORY_SEPARATOR . $item;

            if (is_dir($path)) {
                convertCtpEncode($path);
            }
            else {
            	//文字コードの変換
                $ext = pathinfo($item,PATHINFO_EXTENSION);
                if ( $ext == 'ctp' ) {
                	$content = file_get_contents($path);
                	$content = mb_convert_encoding($content, $to_encoding,$from_enconding);
                	$fp = fopen($path, "w");
                	if ( $fp ) {
                		fwrite($fp, $content);
                	}
                	fclose($fp);
                }


            }
        }
        closedir($handle);

    }

こいつを実行すると、以下のようなエラーが。。

1
PHP Fatal error:  Call to undefined function mb_convert_encoding()

なんかmb_convert_encoding()がないとかいわれておる。。。
ちなみにapacheからPHP動かすと普通につかえます。。

どうやらphp.iniに「extension=mbstring.so」というのがなかったからエラーになってしまったようです。
でもなぜapacheからPHP実行する場合は問題ないんだろ。。

ちなみに環境はMacPortsでいれたphp5.3.6です。

comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。