[Solved] Lower or Upper - PHP Task

  

4
Topic starter

Write a program that prints whether a given character is upper-case or lower case in the ASCII table.

Examples:

lower or upper php task

2 Answers
3

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

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';
}
Share: