/** * 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; }