php-tutorialmade

PHP script to find number of vowels in a string

In this example you are going to learn how to count the number of vowels in a string in PHP. I’m going to show you two methods of finding the vowels from a string, one is using Array and For loop and the other method is using Regex. First method is little bit bigger but will give some ideas about PHP function to the beginners.

Lets see the code (using Array and For loops):

 

The second method is very simple (counting the vowels using preg_match_all()):

I hope you would have liked my post, here is the demo for testing:

demo

 

 

Related Posts

4 thoughts on “PHP script to find number of vowels in a string

  1. can you please help me i dnt get the correct output for counting the vowels can you sent the correct code

Leave a Reply