PHP 统计一个字符串,在另一个字符串中出现次数

简介:
<?php
$str = "This is nice";
echo strlen($str)."<br>"; // 使用 strlen() 来返回字符串长度
echo substr_count($str,"is")."<br>"; // 字符串中 "is" 出现的次数
echo substr_count($str,"is",2)."<br>"; // 字符串缩减为 "is is nice"
echo substr_count($str,"is",3)."<br>"; // 字符串缩减为 "s is nice"
echo substr_count($str,"is",3,3)."<br>"; // 字符串缩减为 "s i"
?>
结果
12
2
2
1
0
目录
相关文章
|
7月前
|
PHP
PHP 字符串
PHP 字符串
25 0
|
1月前
|
JSON JavaScript PHP
PHP把unicode编码的json字符串转中文
PHP把unicode编码的json字符串转中文
13 0