Do While Loop Examples in PHP
In this tutorial, we will learn “do while loop program in PHP”.
Code of program”do while program in PHP”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <html> <body> <form action="" method="post"> <input type="text" name="string" /> <input type="submit" /> </form> </body> </html> <?php if($_POST) { $string = strtolower($_POST['string']); $vowels = array('a','e','i','o','u'); $len = strlen($string); $num = 0; $i=0; do{ if(in_array($string[$i], $vowels)) { $num++; } $i++; } while( $i<$len); function countDigits( $string ) { return preg_match_all( "/[0-9]/", $string ); } substr_count($string, ' '); echo "Number of vowels : <span style='color:green; font-weight:bold;'>". $num."</span>"; echo "<br>"; echo "Number of digits :".countDigits($string); echo "<br>"; echo "Number of spaces :" . substr_count($string," "); } ?> |
The output of code of “do while program in PHP”
