/** * strpos() 函数 * 参数1:要查文本 * 参数2: 查找的字串 * 参数3:从哪里开始查 * return 找到了返回下标位 * 没找到返回 false或者是空 ***/ $text ="enccccyyyy"; $key ='n'; //定义要搜索的字段 echo StrCount($text,$key); function StrCount($Str,$key){ $count = 0; $index = 0; while ( ($index =strpos($Str,$key,$index)) !== false ) { $index= $index+count($key); $count++; } return $count; }