在php中尋找字串出現次數的尋找可以通過substr_count()函數來實現,下面我來給各位同學詳細介紹這些函數了。
substr_count($haystack, $needle [,$offset [,$length]])
/$haystack表示母字串,$needl表示要尋找的字元
//$offset表示尋找的起點,$length表示尋找的長度,均為選擇性參數
執行個體:
| 代碼如下 |
複製代碼 |
$str="this is a test"; echo substr_count($str,'is') .' '; echo substr_count($str,'is',3) .' '; echo substr_count($str,'is',3,3) .' '; ?> |
執行個體:
| 代碼如下 |
複製代碼 |
$str = 'http://www.bkjia.com 愛程式網_軟體編程入門教程_軟體設計交流_字元出現次數'; echo substr_count($str,'w').' '; echo substr_count($str,'t').' '; echo substr_count($str,'愛程式網'); ?> 輸出結果為: //以下是輸出結果 3 2 1 |
再分享一些字串尋找函數
strstr — 尋找字串的首次出現
stristr strstr不區分大小寫版本
strpos -尋找字串首次出現的位置
string substr ( string $string , int $start [, int $length ] )
string strrchr ( string $haystack , mixed $needle )
strripos -計算指定字串在目標字串中最後一次出現的位置(不區分大小寫)
stripos -尋找字串首次出現的位置(不區分大小定)
strrpos -計算指定字串在目標字串中最後一次出現的位置
http://www.bkjia.com/PHPjc/445621.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445621.htmlTechArticle在php中尋找字串出現次數的尋找可以通過substr_count()函數來實現,下面我來給各位同學詳細介紹這些函數了。 substr_count($haystack, $needle [,...