Check Vowel in PHP


Q. Write a PHP program to check whether a character is a vowel or not

<?php
// Define a character
$char = 'E';
$char = strtolower($char); // Convert to lowercase

// Check if the character is a vowel
if ($char == 'a' || $char == 'e' || $char == 'i' || $char == 'o' || $char == 'u') {
    echo "$char is a vowel.";
} else if (ctype_alpha($char)) {
    echo "$char is a consonant.";
} else {
    echo "Invalid input! Please enter an alphabet character.";
}
?> 

Q. Write an algorithm to check vowel or consonant in PHP

1. Start
2. Define a character variable char
3. Convert char to lowercase
4. If char is one of 'a', 'e', 'i', 'o', 'u', then
    → Print "Vowel"
5. Else if char is an alphabet character, then
    → Print "Consonant"
6. Else
    → Print "Invalid input"
7. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.