In PHP, you can use built-in string functions. strpos() Check whether a specified string exists within another string.
Below is how to use it. strpos() Example code for checking whether a specified string exists:
In this example,strpos() The function accepts two parameters: the first is the string to be checked, and the second is the string to be searched for. If the specified string is found, the function returns the index of its first occurrence; if the specified string is not found, it returns `false`. Therefore, we use the `!==` operator to ensure that the returned position index is not equal to `false`.
if $findString Exists $myString In this case, the output will be "The string 'sample' was found in the string 'This is a sample string'." Otherwise, the output will be "The string 'sample' was not found in the string 'This is a sample string'."