[php]substr_count---在一定范围内统计要查找的字符串在另一字符串出现的次数

<?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 1
echo substr_count($text'is'3);

// the text is reduced to 's i', so it prints 0
echo substr_count($text'is'33);

// generates a warning because 5+10 > 14
echo substr_count($text'is'510);


// prints only 1, because it doesn't count overlapped subtrings
$text2 'gcdgcdgcd';
echo 
substr_count($text2'gcdgcd');
?>

posted on 2012-06-26 16:28  小林--2012  阅读(337)  评论(0)    收藏  举报

导航