Press "Enter" to skip to content

PHP Program to Count The Number of Vowels in a String

Here is a PHP program to count the number of vowels in a string “welcome”.

<html>
<body>
<?php 
$count=0;
$a="wellcome";
for($i=0;$i<strlen($a);$i=$i+1)
{
if($a{$i}=='a'||$a{$i}=='e'||$a{$i}=='i'||$a{$i}=='o'||$a{$i}=='u') //here $a{i} will return the character for ith position
{
$count=$count+1;
}
}
echo "The number of vowels are:-".$count;

?>
</body>
</html>

Output: The number of vowels are:- 3

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *