array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.strlen.php', 1 => 'strlen', ), 'up' => array ( 0 => 'ref.strings.php', 1 => '字符串 函数', ), 'prev' => array ( 0 => 'function.stristr.php', 1 => 'stristr', ), 'next' => array ( 0 => 'function.strnatcasecmp.php', 1 => 'strnatcasecmp', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/strings/functions/strlen.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
strlen — 获取字符串长度
string
需要计算长度的字符串。
返回 string
的字节数。
示例 #1 strlen() 示例
<?php
$str = 'abcdef';
echo strlen($str); // 6
$str = ' ab cd ';
echo strlen($str); // 7
?>
注意:
strlen() 返回的是字符串的字节数,而不是其中字符的数量。