What PHP function can be used to search for a specific character in a string?
To search for a specific character in a string in PHP, you can use the strpos() function. This function returns the position of the first occurrence of a specified character or substring within a string. If the character is not found, it returns false. You can use this function to check if a specific character exists in a string and determine its position if it does.
$string = "Hello, World!";
$char = 'o';
$position = strpos($string, $char);
if ($position !== false) {
echo "The character '$char' was found at position $position in the string.";
} else {
echo "The character '$char' was not found in the string.";
}