array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.strlen.php', 1 => 'strlen', ), 'up' => array ( 0 => 'ref.strings.php', 1 => 'Funciones de strings', ), 'prev' => array ( 0 => 'function.stristr.php', 1 => 'stristr', ), 'next' => array ( 0 => 'function.strnatcasecmp.php', 1 => 'strnatcasecmp', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', '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 — Obtiene la longitud de un string
La longitud del string
en caso de éxito,
y 0
si el string
esta vacío.
Versión | Descripción |
---|---|
5.3.0 |
Las versiones anteriores trataban los arrays como el string Array , devolviendo así
una longitud de string de 5 y emitiendo un error de nivel E_NOTICE .
|
Ejemplo #1 Un ejemplo destrlen()
<?php
$str = 'abcdef';
echo strlen($str); // 6
$str = ' ab cd ';
echo strlen($str); // 7
?>
Nota:
strlen() devuelve el número de bytes en lugar del número de caracteres de un string.
Nota:
strlen() devuelve
null
cuando se ejecuta sobre arrays, y emite un error de nivelE_WARNING
.