settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Lower or Upper - PHP Task

+4 votes

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

asked in PHP category by user golearnweb

2 Answers

+3 votes
 
Best answer

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)';
}
answered by user icabe
edited by user golearnweb
+1 vote

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';
}
answered by user eiorgert
...