PHP: How to search and count a specified text in a string?
php
Solution
substr_count() is what you are looking for.
substr_count(strtolower($string), strtolower($searchstring)) would make the count insensitive. (courtesy of gnarf)
Problem
I completely have no idea how to do this as I am not a regexp expert.. But I wanted to search and count a specified CASE-INSENSITIVE text in a long string, for example: the function: ``` int count_string ( string $string_to_search, string $input_search ) ``` example usage and result: ``` $my_string = "Hello my name is John. I love my wife, child, and dog very much. My job is a policeman."; print count_string("my", $my_string); // prints "3" print count_string("is", $my_string); // prints "2" ``` Is there any built-in function to do this? Any kind of help would be appreciated :)