
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP – How to count the number of substring using mb_substr_count()?
In PHP, we can use the function mb_substr_count() to count the total number of substrings in a given string.
Syntax
int mb_substr_count(str $haystack, str $needle, str $encoding)
Parameters
mb_substr_count() accepts three parameters: $haystack, $needle and $encoding.
$haystack− This parameter will check the string.
$needle− This parameter will be used to tell that the substring is found from the given total string.
$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.
Return Values
This will return the number of times the needle substring occurs in the haystack string.
Example
<?php // mb_substr_count function is used $string= mb_substr_count("This is a test", "is"); echo "$string"; ?>
Output
2
- Related Articles
- Python program to count number of substring present in string
- PHP – How to return the character count of a string using iconv_strlen()?
- Count number of Distinct Substring in a String in C++
- How to count the number of faces in OpenCV using C++?
- Program to count number of distinct characters of every substring of a string in Python
- How to Count the Number of Vowels in a string using Python?
- How to count the total number of frames in OpenCV using C++?
- How to count number of Rows and Column using jQuery
- How to count the number of words in a text file using Java?
- How to count the number of lines in a text file using Java?
- How to count the number of times a button is clicked using JavaScript?
- PHP 8 – Using str_contains() to check if a string contains a substring
- PHP to check substring in a string
- PHP – How to get the modulus of an arbitrary precision number using bcmod() function?
- How to count the number of characters (including spaces) in a text file using Java?

Advertisements