Home >Backend Development >PHP Problem >How to use strlen function in php?

How to use strlen function in php?

青灯夜游
青灯夜游Original
2019-10-17 14:18:343313browse

The strlen function is a built-in function in PHP used to get the length of a string; it can calculate the length of a string, including all spaces and special characters; it takes the given string as a parameter and returns its length.

How to use strlen function in php?

#strlen() function returns the length of the string.

Syntax:

strlen(string);

Parameters:

The strlen() function only accepts one parameter string, which is required. This parameter represents the string whose length needs to be returned.

Return value:

strlen() function returns the length of the given string (string), including all spaces and special characters contained in the string; if If the string is empty, 0 is returned.

Example 1:

<?php 
    $str = "hello PHP"; 
      
    // 输出字符串的长度
    echo strlen($str); 
?>

Output:

9

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of How to use strlen function in php?. 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