note 55597 deleted from function.strtoupper by nlopess
| From: | nlopess@php.net | Date: | Sun, 20 May 2007 13:41:19 +0000 |
| Subject: | note 55597 deleted from function.strtoupper by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126725@lists.php.net to get a copy of this message | ||
Note Submitter: ascheinberg at gmail dot com
----
I've searched high and low for a function to test whether or not a string is uppercase. I
wrote this little function to do that.
Set $char equal to the position of the character you want to test, 0 for just the first letter, or
-1 to test if there are any caps at all in the string. This functions returns TRUE if the
character(s) are uppercase or FALSE if the output is not uppercase.
function is_uppercase($str,$char='-1') {
if($char==-1) {
if(strtolower($str) != $str) {
return TRUE;
} else {
return FALSE;
}
} else {
if(strtolower($str{$char}) != $str{$char}) {
return TRUE;
} else {
return FALSE;
}
}
}
How to Use This function:
$test = is_uppercase("Test",-1); //returns TRUE
$test = is_uppercase("Test",0); //returns TRUE
$test = is_uppercase("Test",1); //returns FALSE
$test = is_uppercase("this is a string!"); //returns FALSE
$test = is_uppercase("this is a string!",-1); //returns FALSE
$test = is_uppercase("this is a string!",5); //returns FALSE