How can one check if a string contains uppercase characters in PHP?
To check if a string contains uppercase characters in PHP, you can use the `preg_match` function with a regular expression pattern that matches uppercase letters. The pattern `[A-Z]` will match any uppercase letter in the string. If `preg_match` returns a positive integer, it means that the string contains at least one uppercase letter.
$string = "Hello World";
if (preg_match('/[A-Z]/', $string)) {
echo "String contains uppercase characters.";
} else {
echo "String does not contain uppercase characters.";
}
Keywords
Related Questions
- What is the purpose of using the mysql_num_rows() function in PHP when checking for query results?
- How can using associative arrays in PHP improve data handling compared to storing data in individual variables?
- Are there any specific PHP functions or methods that can simplify the process of alternating colors in a loop?