ホーム > PHPサンプル > 文字列系 > PHP 文字列を検索して出現回数を調べたい
PHPサンプル

UPDATE:2017年09月27日

PHP 文字列を検索して出現回数を調べたい

substr_count() 文字列の出現数を調べる PHPサンプルコード[ php sample code ] | wepicks!
PHP4 PHP5 PHP7

文字列の出現数を調べる substr_count()

出現回数の数値 = substr_count (検索対象文字列, 検索する文字列);

例:

結果は

2

となります。

substr_count('検索対象文字','検索する文字列') 検索対象文字 の中での 検索する文字列 の出現回数を返します。
POINT
※大文字小文字を区別する


サンプルコード

– サンプル Click Here ! –

– サンプル Click Here ! –

実行結果
文字列の出現数を調べる「substr_count()」
2

文字列の出現数を調べる「substr_count()」4文字目から検索
1

文字列の出現数を調べる「substr_count()」4文字目から3文字検索
0

文字列の出現数を調べる「substr_count()」6文字目から10文字検索

文字列の出現数を調べる「substr_count()」重なった場合
1


タグ(=記事関連ワード)

日付

投稿日:2012年3月4日
最終更新日:2017年09月27日

このカテゴリの他のページ

この記事へのコメント

トラックバックurl

https://wepicks.net/phpsample-string-substr_count/trackback/

page top

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny