Home > Backend Development > PHP Problem > Which function in php can get the length of a string?

Which function in php can get the length of a string?

步履不停
Release: 2023-02-23 08:48:01
Original
6040 people have browsed it

Which function in php can get the length of a string?

php get string length function strlen and mb_strlen
count() - Count in the array The number of units, or the number of attributes in the object
strlen - Get the length of the string, a Chinese character is 3 characters
mb_strlen() - Get the length of the string

-----------
int strlen (string $string)
Returns the length of string if successful; if string is empty, returns 0.

Example

<?php
$str = &#39;abcdef&#39;;
echo strlen($str); // 6
$str = &#39;abcdef中国&#39;;
echo strlen($str); // 12
echo mb_strlen($str);//12
echo count($str);//1
$str = &#39; ab cd &#39;;
echo strlen($str); // 7
?>
Copy after login

Note:
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.

For more PHP-related technical articles, please visit the PHP Tutorial column to learn!

The above is the detailed content of Which function in php can get the length of a string?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template