<?php
function str_sub($parstr,$substr){
$par_str = strlen($parstr); #父字符串的长度
$sub_str = strlen($substr); #子字符串的长度 用于判断是否已经在父字符串里查找完毕
# 子字符串开始查找的偏移长度 大于 父字符串的长度 就表示已经查找到底部了
$num = 0;
$poi = 0;
#出现次数累计变量
while ( $poi < $par_str ) { //
if (strpos($parstr,$substr,$poi) !== false) {
# code...
$poi = strpos($parstr, $substr,$poi);
$poi += $sub_str;
$num++;
}
}
echo "${substr}出现次数为" . $num . "次" ;
}
$str = 'how are you! fine thank you,fine, may be you are right, 256, I dont think so,let me see,I can not fine';
str_sub($str,'fine');
?>