What\'s the best way to see if a string contains all capital letters? I still want the function to return true if the string also contains symbols or numbers.
Check whether strtoupper($str) == $str
To handle non-ascii use:
mb_strtoupper($str, 'utf-8') == $str
This is how I handle ALL CAPS text for my comments section.
if ($str == strtoupper($str))
{
$str = ucfirst(strtolower($str));
}
If you want numbers included (and by "symbols" most everything else), then what you are actually trying to test for is the absence of lowercase letters:
$all_upper = !preg_match("/[a-z]/", $string)