There are multiple ways to search strings in PHP, each suitable for different scenarios. The following sections explain the commonly used methods along with example code.
Purpose: Finds the first occurrence of a specified substring in a string. Returns false if not found.
Syntax: strpos(string, substring, offset)
Parameters:
Example:
$string = "Hello World";
$substring = "World";
$pos = strpos($string, $substring);
if ($pos !== false) {
    echo "Substring found at position $pos";
} else {
    echo "Substring not found";
}Purpose: Similar to strpos() but performs a case-insensitive search.
Syntax: stripos(string, substring, offset)
Parameters are the same as strpos().
Purpose: Finds the last occurrence of a specified substring in a string. Returns false if not found.
Syntax: strrpos(string, substring, offset)
Parameters are the same as strpos().
Purpose: Searches for a specified substring in a string and returns the portion of the string starting from the substring, case-insensitive. Returns false if not found.
Syntax: stristr(string, substring, ignore_case)
Parameters:
Purpose: Similar to stristr() but case-sensitive.
Syntax: strstr(string, substring, ignore_case)
Parameters are the same as stristr().
By using these methods, developers can choose the appropriate function based on actual requirements and handle PHP string searches efficiently.