strlen()是PHP中的内置函数,该函数返回给定字符串的长度。它以字符串作为参数并返回其长度。它计算包括所有空格和特殊字符的字符串的长度。
用法:
strlen($string)
参数:strlen()函数仅接受一个必需的参数$string。此参数表示需要返回其长度的字符串。
返回值:该函数返回$string的长度,包括所有空格和特殊字符。
例子:
Input : "abc"
Output : 3
Input : "\n chetna ;"
Output : 10
Explanation : '\n' is considered as a single character
              as it is an escape sequence.
Input : "geeks for geeks" 
Output :15
以下示例程序旨在说明PHP中的strlen()函数:
程序1:下面的程序演示了PHP中strlen()函数的用法。
<?php 
    // PHP program to find the  
    // length of a given string  
      
    $str = "geeks for geeks"; 
      
    // prints the length of the string  
    // including the space  
    echo strlen($str); 
?> 输出:
15
程序2:下面的程序演示了PHP中strlen()函数的使用,其中字符串具有特殊字符和转义序列。
<?php 
    // PHP program to find the  
    // length of a given string which has  
    // special characters 
      
    $str = "\n chetna ;"; 
      
    // here '\n' has been counted as 1  
    echo strlen($str); 
?>输出:
10
参考:
http://php.net/manual/en/function.strlen.php
相关用法
- p5.js str()用法及代码示例
- PHP Ds\Map get()用法及代码示例
- p5.js value()用法及代码示例
- p5.js second()用法及代码示例
- p5.js nf()用法及代码示例
- p5.js int()用法及代码示例
- p5.js max()用法及代码示例
- d3.js d3.max()用法及代码示例
- p5.js sq()用法及代码示例
- p5.js nfs()用法及代码示例
- PHP each()用法及代码示例
- p5.js nfp()用法及代码示例
注:本文由纯净天空筛选整理自ChetnaAgarwal大神的英文原创作品 PHP | strlen() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
