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