This should be somewhat simpler, since a string can be seen as an array of characters (though in PHP an array isnt really an array so....)
function numUpper($string) {
$len = strlen($string);
$total = 0;
for ($i = 0; $i < $len; $i++) {
if (ctype_upper($string{$i})) {
$total++;
}
}
return $total;
}
in which case after defining the function you can use:
$str = 'StriNG';
echo numUpper($str);
Incidentally, nunomira, your example wont work, since the uppercase letters start at ASCII 65
It will have to be modified slightly to take that into account.