strlen 获取字符串长度

发表日期:2021-07-01 10:23:24 | 来源: | | 浏览(995) 分类:字符串 函数

strlen

(PHP 4, PHP 5, PHP 7, PHP 8)

strlen获取字符串长度

说明

strlen(string $string): int

返回给定的字符串 string 的长度。

参数

string

需要计算长度的字符串

返回值

成功则返回字符串 string 的长度;如果 string 为空,则返回 0。

更新日志

版本 说明
5.3.0 Prior versions treated arrays as the string Array, thus returning a string length of 5 and emitting an E_NOTICE level error.

范例

示例 #1 strlen() 范例

<?php 
$str = 'abcdef';
echo strlen($str);
 // 6$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.

参见

  • count() - 计算数组中的单元数目,或对象中的属性个数
  • mb_strlen() - 获取字符串的长度

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。