php獲取字符串長度函數strlen和mb_strlen
count() - 計算數組中的單元數目,或對象中的屬性個數
strlen — 獲取字符串長度,一個漢字為3個字符
mb_strlen() - 獲取字符串的長度
-----------
int strlen ( string $string )
成功則返回字符串 string 的長度;如果 string 為空,則返回 0。
范例
<?php $str = 'abcdef'; echo strlen($str); // 6 $str = 'abcdef中國'; echo strlen($str); // 12 echo mb_strlen($str);//12 echo count($str);//1 $str = ' ab cd '; echo strlen($str); // 7 ?>
注意:
strlen() returns the number of bytes rather than the number of characters in a string.
strlen() returns NULL when executed on arrays, and an E_WARNING level error is emitted.
代碼在線運行 - 在線工具
http://tool.lu/coderunner/