在php中查找字符串出現次數的查找可以通過substr_count()函數來實現,下面我來給各位同學詳細介紹這些函數了.
substr_count($haystack, $needle [,$offset [,$length]])
/$haystack表示母字符串,$needl表示要查找的字符
//$offset表示查找的起點,$length表示查找的長度,均為可選參數
實例,代碼如下:
- <?php
- $str="this is a test";
- echo substr_count($str,'is') .'<br>';
- echo substr_count($str,'is',3) .'<br>';
- echo substr_count($str,'is',3,3) .'<br>';
- ?>
實例,代碼如下:
- <?php
- $str = 'http://www.49028c.com 愛程序網_軟件編程入門教程_軟件設計交流_字符出現次數';
- echo substr_count($str,'w').'<br />';
- echo substr_count($str,'t').'<br />';
- echo substr_count($str,'愛程序網');
- ?>
- //輸出結果為:
- //以下是輸出結果
- 3
- 2
- 1
再分享一些字符串查找函數
新聞熱點
疑難解答