..


Sponsored Links

substr_count

Substr_count function returns the number of occurrences of one string within another string. The function substr_count admits 4 parameters:

  • where to look;
  • what to look for;
  • starting character (optional);
  • number of characters to search (optional);
For example:





 $ Where = "mrwebmaster is the portal of the Italian webmaster";







 $ What = "webmaster";







 echo substr_count ($ where, $ what);



produce as output 2.

In our example we have omitted the two optional parameters. We make two further examples of integrating these parameters:
 



 echo substr_count ($ where, $ what, 3);

 
In this case the output is 1 in 3 as specifying the starting character of the string $ where it is reduced (ebmaster is the portal of the Italian webmasters) and the string "webmaster" is to be found only once.

Now we integrate the fourth parameter:
 



 echo substr_count ($ where, $ what, 3, 20);

 
In this case, the output will be 0 because the string was further reduced (ebmaster is the portal) and the string $ search is not found.

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links