What is the use of substr_count() in PHP?
The substr_count() function counts how many times a small text (substring) is found in a bigger string.
<?php
echo substr_count("hello world, hello PHP", "hello") . "<br>";
// Overlapping matches are not counted twice
echo substr_count("aaa", "aa");
?>
Output:
Tutorials Class - Output Window
2
1
- It is case-sensitive. “Hello” and “hello” are different.
- It does not count overlapping matches.
- To count the words of a string use
str_word_count(), and to count array elements usecount().
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |