PHP STR_CONTAINS ( )To check if a String Contains a Substring in PHP STRING: A set of characters can be called string. For example ' H ' is a character and when we use " H " in " HELLO HARRY " it becomes a string and the character " H " can be treated as an element of string . A string is not only a single set of characters it contains multiple substrings in it. Also we can conclude that all substrings are a subset of string, but a string can b=never be a subset of a substring. STR_CONTAINS (): - To check whether a parent string contains a substring, PHP provides us with an inbuilt function called str_contains (), which helps the developer identify the parent string contains a given substring or not. PHP str_contains () function evaluates the substring is contained in the parent string anywhere. Then there is a substring the function will return a TRUE value else it will respond to a False value Syntax: Parameters:
Example 1: Output: In the above program, we have declared a variable $string with string value and used str_contains() function to find the word "s/tring" and declared the if and else statement on the bases of values returned from str_contains() function Example 2: Output: Here in this program, we have declared a variable $string with string value and used str_contains() function to find the word "string" and declared the if and else statement on the bases of values returned from the str_contains() function DISADVANTAGES OF STR _ CONTAINS () FUNCTION
ALTERNATE FUNCTION LIKE STR _ CONTAINS ()To overcome the disadvantage of str _contains, PHP introduced a new set of functions that not only check whether the given string contains a substring. They also state exactly where the substring is located by providing us with the index of the substring.
STROPS - this function is used to return the index of the searched substring Syntax Parameters:
For example : Output: In the above program, we have declared a variable $input_string with string value and used strpos() function to find the word "string" and declared the if and else statement on the bases of values returned from the strpos() function STRIPS - This function is used to return the first index of the searched substring Syntax Parameters:
Example of STRIPS Function: Output: Here in the above program, we have declared a variable $string and $search with string value and used stripos() function to find the word "string" and its position and declared the if and else statement on the bases of values returned from stripos() function STRROPS - this function is used to return the last index of the searched substring Syntax Parameters:
Example of STRROPS Function: Output: Next TopicMultiple Inheritance in PHP |