note 55597 added to function.strtoupper

From: Date: Mon, 08 Aug 2005 16:21:29 +0000
Subject: note 55597 added to function.strtoupper
Groups: php.notes 
Request: Send a blank email to php-notes+get-93252@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.strtoupper.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55597 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55597&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55597&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55597&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55597&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55597&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55597&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55597&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93252) next »