search
HomeBackend DevelopmentPHP ProblemWhich function in php can get the length of a string?

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

Jun 24, 2019 pm 02:40 PM
phpfunctionstring length

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
?>

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!

Statement
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use