Category:php functions

substr_count

How to use substr_count()

int substr_count ( string $haystack , string $needle [, int $offset= 0 [, int $length ]] )

substr_count ( string $haystack , string $needle [, int $offset= 0 [, int $length ]] )

Is a php function looks for instances of

A String Within a String.

It returns how many instances are found.

The example below is using a string called "tested_string".

A variable "$cnt" to catch the return value.

And the "if()" control to check for a number greater than 0.



if ($cnt = substr_count('tested_string','test')> 0){

echo "yes test is in there $cnt times";

}
Author: D.Shaun Morgan