• 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

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文字あります。
<<--

posted by akanuma akanuma on Sat 14 Jul 2012 at 20:28 with 0 comments