How can preg_match be used to allow only uppercase words with lowercase letters following in PHP?

To allow only uppercase words with lowercase letters following in PHP using preg_match, you can use the regular expression pattern "/^[A-Z][a-z]*$/" in the preg_match function. This pattern ensures that the string starts with an uppercase letter followed by zero or more lowercase letters. If the preg_match function returns 1, it means the string matches the pattern, indicating that it contains only uppercase words with lowercase letters following.

$string = "Hello world";
if(preg_match("/^[A-Z][a-z]*$/", $string)) {
    echo "String contains only uppercase words with lowercase letters following.";
} else {
    echo "String does not match the pattern.";
}