How can the strpos function in PHP be utilized to search for a substring within a string and return true if found?

To search for a substring within a string and return true if found, you can use the strpos function in PHP. This function returns the position of the first occurrence of a substring within a string, or false if the substring is not found. You can then check if the result is not equal to false to determine if the substring exists in the string.

$string = "Hello, World!";
$substring = "World";

if (strpos($string, $substring) !== false) {
    echo "Substring found!";
} else {
    echo "Substring not found.";
}