Write a PHP program to check whether a character is an alphabet or not by using the if-else statement and using the conditional operator
ADVERTISEMENTS
Write a php program to check whether a character is an alphabet or not by using the if-else statement and using the conditional operator. Here you'll learn how to check whether a character is an alphabet or not by using the if-else statement and using the conditional operator.
1. PHP program to check whether a character is an alphabet or not by using the if-else statement:
<?php
// PHP program to check whether a character is an
// alphabet or not by using the if-else statement
$x = 'j';
if (($x >= 'a' && $x <= 'z') || ($x >= 'A' && $x <= 'Z')) {
echo $x . " is an alphabet character.\n";
} else {
echo $x . " is not an alphabet character.\n";
}
?>
Output:
j is an alphabet character.
2. PHP program to check whether a character is an alphabet or not by using the conditional operator:
<?php
// PHP program to check whether a character is an
// alphabet or not by using the conditional operator
$x = 7;
$f = NULL;
$f = ($x >= 'a' && $x <= 'z') || ($x >= 'A' && $x <= 'Z') ? 1 : 0;
if ($f) {
echo $x . " is an alphabet character.\n";
} else {
echo $x . " is not an alphabet character.\n";
}
?>
Output:
7 is not an alphabet character.
Tags:
# write a program to check whether the given input is an alphabet, number, or special character in php language