mb_strwidth
文字列の幅を返します
関数名:mb_strwidth()
該当するバージョン:PHP 4> = 4.0.6、PHP 5、PHP 7
関数の説明:mb_strwidth()関数は、指定された文字列(文字内)の幅を返し、マルチバイト文字セットエンコーディングを使用します。
使用法:
mb_strwidth ( string $str [, string $encoding = mb_internal_encoding() ] ) : int
パラメーター:
返品値:
例:
$str = "你好,世界!"; $width = mb_strwidth($str, 'UTF-8'); echo "字符串的宽度为:$width"; // 输出:字符串的宽度为:7
上記の例では、mb_strwidth()関数を使用して、漢字を含む文字列の幅を計算します。漢字の幅は2文字であるため、結果は7です。