We are given two strings.We have to check whether the second string is a sub-string of the first string or not using PHP inbuilt function strpos().
Input :$s1 = "geeksforgeeks" $s2 = "for" Output : True Explanation : The string "for" is a substring of the string Matthew so output is true. Input :$s1 = "practice.geeksforgeeks" $s2 = "quiz" Output : False
The problem can be solved by iterating through the given string from 0 index to final length of the string and comparing the query string with the iterations. But in PHP we can also make use of some inbuilt functions to solve this particular problem.
- strpos(): This function finds the position of the first occurrence of a string inside another string.
- strlen() : Returns length of string.
If the index of first occurrence of the given string is within the length indices of the given string then the output returns true else the output returns false.
- PHP | Program to check a string is a rotation of another string
- PHP | Palindrome Check
- PHP | check if a number is Even or Odd
- How to check whether an array is empty using PHP?
- PHP | Check if a number is prime
- PHP program to check for Anagram
- PHP | ctype_alnum() (Check for Alphanumeric)
- HTML | Spell Check
- PHP | Check if all characters are lower case
- How to check an array is associative or sequential in PHP?
- Check whether a given Number is Power-Isolated or not
- PHP | Different characters in the given string
- How to get the last n characters of a PHP string?
- PHP | String Functions
- PHP | Reverse a String
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.