【php】substr_count()函数
昨天想统计一下tianya帖子的回复数,就想统计一下一段字符中某段字符出现的次数,就百度了一下下,当然找到了这个函数拉~~~substr_count()
官方说明:http://cn.php.net/manual/zh/function.substr-count.php
hihi,here we go~~~~~~~~~
说明:
int substr_count ( string $haystack, string
$needle [, int $offset [, int $length]] )
substr_count() returns the number of times the
needle substring occurs in the haystack string. please note that
needle is case sensitive.
贴个例子比什么都说明问题。见下:
echo substr_count($text, ‘is’); // 2
// the string is reduced to ’s is a test’, so it prints 1
echo substr_count($text, ‘is’, 3);
// the text is reduced to ’s i’, so it prints 0
echo substr_count($text, ‘is’, 3, 3);
// generates a warning because 5+10 > 14
echo substr_count($text, ‘is’, 5, 10);
// prints only 1, because it doesn’t count overlapped subtrings
$text2 = ‘gcdgcdgcd’;
echo substr_count($text2, ‘gcdgcd’);
?>
本文来自苏南的博客, 转载请注明网址:http://newsn.net, 谢谢!
我的淘宝小店:http://68zz.com
我的Sina圈子:http://q.blog.sina.com.cn/pctalk
