php獲取字符串長度函數strlen和mb_strlen


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/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM