substr_count() function in PHP


The substr_count() function is used to count the number of sub-strings.

Syntax

substr_count(str,substr,begin,len)

Parameters

  • str − The string to check

  • substr − The string to search for

  • begin − Where to begin searching in the string

  • len − The length of the search

Return

The substr_count() function returns the number of times substring occurs in the string.

Example

The following is an example −

Live Demo

<?php
   $str = 'This is our example!'; echo strlen($str);
   echo "
"; echo substr_count($str, 'our'); ?>

Output

20
1

Updated on: 30-Jul-2019

99 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements