PHP – 如何使用 iconv_strlen() 返回字串的字元數?
在 PHP 中,**iconv_strlen()** 函式用於返回給定字串的字元數。這是 PHP 中的一個內建函式,首次用於 PHP 5 版本。從 PHP 8.0 開始,編碼是可空的。
語法
string iconv_strlen(str $string, str $encoding)
引數
此 PHP 函式接受兩個引數:**$string** 和 **$encoding**。
**$string−** $string 引數用於輸入字串。
**$encoding− **如果 $encoding 引數不存在或為 null,則假定字串使用 **iconv.internal_encoding** 編碼。
返回值
**iconv_strlen()** 函式返回給定字串中存在的字元計數列表,或者如果編碼過程中發生錯誤則返回 False。
示例
<?php //UTF-8 string $integer = iconv_strlen("hello world!", "UTF-8"); // It will returns the number of character var_dump($integer); ?>
輸出
int(12)
廣告