Hi all,
How do I check if a string is all uppercase?
And if it is I want to make it bold (apply a css style to it)
I was using something like this...
if (strtoupper($date)) { td { font-weight: bold; } }
there are functions in the manual below the explanation of strtoupper: www.php.net/strtoupper
if you convert a string to upper case and it doesn't change compared to the way it looked like before... it's already uppercase
if (strtoupper($the_string) == $the_string) { echo '$the_string contains only upper case letters and maybe other non-letter characters'; }
And your styling will not work like that: you are trying to use CSS style notation in HTML tag properties and the syntax is different. Do it properly with a CSS class
echo '<td'; if (strtoupper($date)) { echo ' class="boldTxt"'; } echo '>';
From PHP 4.0.4., there is [man]ctype_upper/man which may be what you are looking for with respect to the way non-letter characters are treated.
Yup. ctype_upper is the one!. Cheers guys.
mrhappiness wrote:if you convert a string to upper case and it doesn't change compared to the way it looked like before... it's already uppercaseif (strtoupper($the_string) == $the_string) { echo '$the_string contains only upper case letters and maybe other non-letter characters'; }
Bravo old chap. Much neater than the way I was thinking
It took you three years to think it though? 🙂