php 尋找字串出現次數函數介紹_PHP教程

來源:互聯網
上載者:User
在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 [,...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.