We are given two strings s1 and s2. We need to find the number of occurrences of s2 in s1.
Input : $s1 = "geeksforgeeks", $s2 = "geeks" Output : 2 Explanation : s2 appears 2 times in s1 Input : $s1 = "Hello Shubham. how are you?"; $s2 = "shubham" Output : 0 Explanation : Note the first letter of s2 is different from substrings present in s1.
The problem can be solved using PHP in built function for counting the number of occurrences of a substring in a given string.The in built function used for the given problem is:
- substr_count(): The substr_count() function counts the number of times a substring occurs in a string.
Note: The substring is case-sensitive.
- PHP to check substring in a string
- Program to find the number of days between two dates in PHP
- PHP | Check if a number is Perfect number
- PHP | Check if a number is armstrong number
- PHP | Find Intersection of two arrays
- PHP program to find the Standard Deviation of an array
- PHP program to find the maximum and the minimum in array
- PHP program to find missing element(s) from an array
- PHP program to find the length of the last word in string
- PHP | Factorial of a number
- PHP | Sum of digits of a number
- PHP | check if a number is Even or Odd
- How to convert a string into number in PHP?
- PHP | Check if a number is prime
- PHP | Number of week days between two dates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.