PHP程序,用于查找字符串中的字符数
要查找字符串中的字符数,PHP 代码如下所示 -
示例
<?php $my_string = "Hi there, this is a sample "; $len = mb_strlen($my_string); print_r("The number of characters in the string is "); echo $len; ?>
输出
The number of characters in the string is 27
上面定义了一个字符串,它在中间有多于所需的空格 -
$my_string = "Hi there, this is a sample ";
接下来,使用“strlen”函数计算字符串的长度。此长度被分配给一个变量。这将提供字符串中存在的字符,包括空格 -
$len = mb_strlen($my_string);
然后将计算出的长度打印在屏幕上 -
print_r("The number of characters in the string is "); echo $len;
广告