好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php substr_count字符出现次数统计函数 - php函数

php substr_count字符出现次数统计函数

这里主要是介绍一个实用的php substr_count()函数,统计字符串中一个字符出现的次数,有需要的朋友可以参考。

substr_count(string,substring,start,length)

参数 描述 

string 必需。规定要检查的字符串。 

substring 必需。规定要检索的字符串。 

start 可选。规定在字符串中何处开始搜索。 

length 可选。规定搜索的长度。

代码如下:

<?php    $str = "ni hao ,wo jiao wang hui ,lai zi an hui chao hu" ;    echo   "原字符串:" . $str . "<br />" ;    $str1 =substr_count( $str , 'i' ); //substr_count():统计字符串在函数中出现的次数     echo   "使用substr_count()之后:" . $str1 . "<br />" ;    $str2 =substr_count( $str , 'i' ,6); //substr_count($str,'i',6):从第6个字符串开始统计,后面还跟数字的话,就是统计多少个,如果不加的话,默认是到最后     echo   "使用substr_count()之后:" . $str2 . "<br />" ;    ?> 

查看更多关于php substr_count字符出现次数统计函数 - php函数的详细内容...

  阅读:49次