2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > php计算子串在字符串中出现次数的函数substr_count()

php计算子串在字符串中出现次数的函数substr_count()

时间:2023-03-11 10:12:38

相关推荐

php计算子串在字符串中出现次数的函数substr_count()

后端开发|php教程

php,字符串,串在

后端开发-php教程

免费下游戏源码的网站,VSCode会重复下载,ubuntu 响应慢,安卓系统tomcat,爬虫仔,linux php编辑器,萧山seo整站推广方案,国外图片分享有什么网站源码,第4套杰奇wap小说模板lzw

实例

游戏转换器易语言源码,vscode前端基础知识,ubuntu源搜索,怎么把tomcat停掉,爬虫论文报告,php tls1.2,江西站外seo优化数据,怎么仿网站页面,数值策划模板lzw

计算 “world” 在字符串中出现的次数:

asp源码2种,vscode作品,UBUNTU系统下载壁纸,编译tomcat,sqlite 统计语句,iis服务器无法访问,jquery slide插件,web前端桌面框架,qq空间日志爬虫,厦门php培训机构,seo综合优化平台,网站源代码 百度云,网页 flash 代码,订餐系统模板,html页面分页实现,java企业人事管理系统,可以下程序的网站lzw

substr_count() 函数计算子串在字符串中出现的次数。

注释:子串是区分大小写的。

注释:该函数不计数重叠的子串(参见实例 2) 。

注释:如果 start 参数加上 length 参数大于字符串长度,该函数则生成一个警告(参见实例 3)。

语法

substr_count(string,substring,start,length)

技术细节

更多实例

实例 1

使用所有的参数:

<?php$str = "This is nice";echo strlen($str)."

"; // Using strlen() to return the string lengthecho substr_count($str,"is")."

"; // The number of times "is" occurs in the stringecho substr_count($str,"is",2)."

"; // The string is now reduced to "is is PHP"echo substr_count($str,"is",3)."

"; // The string is now reduced to "s is PHP"echo substr_count($str,"is",3,3)."

"; // The string is now reduced to "s i"?>

实例 2

重叠的子串:

实例 3

如果 start 和 length 参数超过字符串长度,该函数则输出一个警告:

由于长度值超过字符串的长度(3 + 9大于12)。所以这将输出一个警告。

举例:

<?php$text = This is a test;echo strlen($text) .

; // 输出14 echo substr_count($text, is) .

; // 2 // the string is reduced to s is a test, so it prints 1echo substr_count($text, is, 3) .

;//实际上就是从第四个字符开始查找是否在$text中含有is // the text is reduced to e , so it prints 0echo substr_count($text, are, 16, 3) .

; // the text is reduced to s i, so it prints 0echo substr_count($text, is, 3, 3); // generates a warning because 5+10 > 14echo substr_count($text, is, 5, 10) .

; // prints only 1, because it doesn count overlapped subtrings$text2 = gcdgcdgcd;echo substr_count($text2, gcdgcd) .

; ?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。