How can the strpos() function be used to determine if a string starts with a specific substring in PHP?
To determine if a string starts with a specific substring in PHP, you can use the strpos() function to check if the index of the substring in the main string is 0. If the index is 0, then the substring is at the beginning of the main string. If the index is false or greater than 0, then the substring is not at the beginning.
$string = "Hello World";
$substring = "Hello";
if (strpos($string, $substring) === 0) {
echo "The string starts with the substring.";
} else {
echo "The string does not start with the substring.";
}