导航首页 » 技术教程 » PHP字符串函数strlen()的用法
PHP字符串函数strlen()的用法 145 2023-12-11   

strlen

(PHP 4, PHP 5)

strlen — 获取字符串长度

说明

int strlen ( string $string )

返回给定的字符串 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.

范例

Example #1 strlen() 范例

<?php
$str = 'abcdef';
echo strlen($str); // 6

$str = ' ab cd ';
echo strlen($str); // 7
?>

注释

Note:

strlen() returns the number of bytes rather than the number of characters in a string.

Note:

strlen() returns NULL when executed on arrays, and an E_WARNING level error is emitted.

参见

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


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103