- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements