![]() |
A string is a collection of given characters and a substring is a string present in a given string. In this article, we are going to check if the given string contains a substring by using the PHP strpos() function. Syntax: strpos($original_string,$sub_string); Parameters:
Return type: Boolean value
Example:
Output: True Example 2:
Output: False Example 3: The following example also considers space.
Output: True Example 4:
Output: False Using substr_count functionThe substr_count function in PHP efficiently counts the occurrences of a substring within a string. It returns the total count of occurrences, allowing for simple checks of substring presence or frequency within the given string. Example:
Output Substring found Using preg_match FunctionThe preg_match function in PHP is used to perform a regular expression match. It returns the number of times the pattern matches (which will be 1 if it matches and 0 if it doesn’t). Example:
Output True |
Reffered: https://www.geeksforgeeks.org
PHP |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 8 |