Problem:- How to Count Vowels in a String Using PHP?
Solution – Count Vowels in a String Using PHP
<?php $string = 'Hello User! I Am a PHP Script'; $vowels = 0; for($i = 0, $j = strlen($string) ; $i< $j ; $i++){ if(strstr('aeiouAEIOU', $string[$i])){ $vowels++; } } echo $vowels; ?>
How it Works?
The function strlen() used to total length for the loop and strstr() is used to check the single string is available in main string or not. if yes then we increase $vowels value and finally we will get 8 vowels in $string.
इसे भी पढ़े – Loco App से पैसे कैसे कमायें?