How can the PHP function strpos() be used to check for specific characters in a string?

The PHP function strpos() can be used to check for specific characters in a string by returning the position of the first occurrence of a substring within a string. To check for specific characters, you can use strpos() to search for the character or substring you are looking for in the given string. If the function returns a position greater than or equal to 0, it means the character or substring is present in the string.

$string = "Hello, World!";
$charToCheck = "o";

if (strpos($string, $charToCheck) !== false) {
    echo "The character '$charToCheck' is present in the string.";
} else {
    echo "The character '$charToCheck' is not present in the string.";
}