4
05/11/2024 12:56 pm
Topic starter
Write a program that prints whether a given character is upper-case or lower case in the ASCII table.
Examples:
2 Answers
3
05/11/2024 12:57 pm
To check for lower or upper case, you can also use ctype functions (lines #5 and #7):
ctype_upper() and ctype_lower()
Code:
<?php $char = readline(); if (ctype_upper($char)) { echo 'upper-case'; } else if (ctype_lower($char)) { echo 'lower-case'; } else { echo 'not alphabetical letter or not consistent char(s)'; }
1
05/11/2024 12:58 pm
My solution with ord() function:
?php $char = readline(); $ascii = ord($char); if ($ascii >= 65 && $ascii <= 90) { echo 'upper-case'; } else if ($ascii >= 97 && $ascii <= 122) { echo 'lower-case'; }