[PHP] yum で php-mbstring をインストール
PHPを勉強中なわけですが、下記のようなスクリプトを書いたところ、mb_strlen という関数が使えませんでした。
php>>
<?php
echo "テキストを入力:";
$a = trim(fgets(STDIN));
echo mb_strlen($a, 'utf-8') . "文字あります。";
?>
<<--
sh>>
$ php hello.php
テキストを入力:hello
PHP Fatal error: Call to undefined function mb_strlen() in /home/akanuma/scripts/php/hello.php on line 5
<<--
ググってみるとどうやらマルチバイトの処理ができるようにするには、コンパイル時にパラメータ追加したりとか、php.ini に設定の追加が必要とか色々ありましたが、yum で php-mbstring をインストールすればよさそうということで実行。
sh>>
yum install php-mbstring
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
- base: ftp.iij.ad.jp
- epel: ftp.kddilabs.jp
- extras: ftp.iij.ad.jp
- remi: rpms.famillecollet.com
- updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-mbstring.x86_64 0:5.3.14-1.el5.remi set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================
Package Arch Version Repository Size
Installing:
php-mbstring x86_64 5.3.14-1.el5.remi remi 2.3 M
Transaction Summary
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 2.3 M
Is this ok [y/N]: y
Downloading Packages:
php-mbstring-5.3.14-1.el5.remi.x86_64.rpm | 2.3 MB 00:04
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : php-mbstring 1/1
Installed:
php-mbstring.x86_64 0:5.3.14-1.el5.remi
Complete!
<<--
これで無事に mb_strlen が使えるようになりました。
sh>>
$ php hello.php
テキストを入力:はろー
3文字あります。
<<--