在本文中,我们将看到如何使用 斯特伦() 函数,并通过示例了解其实现。
null
这个 斯特伦() 是PHP中的一个内置函数,返回给定字符串的长度。它将字符串作为参数并返回其长度。它计算字符串的长度,包括所有空格和特殊字符。
语法:
strlen($string);
参数: strlen()函数只接受一个参数 $string 这是强制性的。此参数表示需要返回其长度的字符串。
返回值: 该函数返回 $string 包括所有空格和特殊字符。
下面的程序演示了PHP中的strlen()函数:
例1: 下面的示例演示了 斯特伦() 函数。
PHP
<?php // PHP program to find the // length of a given string $str = "GeeksforGeeks" ; // prints the length of the string // including the space echo strlen ( $str ); ?> |
输出:
13
例2: 这个例子演示了 斯特伦() 函数,其中字符串具有特殊字符和转义序列。
PHP
<?php // PHP program to find the // length of a given string which has // special characters $str = " GeeksforGeeks Learning;" ; // here '' has been counted as 1 echo strlen ( $str ); ?> |
输出:
25
参考 : http://php.net/manual/en/function.strlen.php
PHP是一种专门为web开发设计的服务器端脚本语言。通过以下步骤,您可以从头开始学习PHP PHP的教程 和 PHP示例 .
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END