Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php <!DOCTYPE html> <html> <head> <title>Vowel Counter</title> </head> <body> <h2>Enter a String</h2> <form method="post"> <input type="text" name="inputString" required> <input type="submit" value="Submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { function countVowels($str) { $str = strtolower($str); // Make it case-insensitive $vowels = ['a', 'e', 'i', 'o', 'u']; $total = 0; $occurrences = array_fill_keys($vowels, 0); for ($i = 0; $i < strlen($str); $i++) { $char = $str[$i]; if (in_array($char, $vowels)) { $occurrences[$char]++; $total++; } } return [$total, $occurrences]; } $input = $_POST['inputString']; list($totalVowels, $vowelCounts) = countVowels($input); echo "<h3>Input String: " . htmlspecialchars($input) . "</h3>"; echo "<p>Total Number of Vowels: $totalVowels</p>"; echo "<p>Occurrences of Each Vowel:</p>"; echo "<ul>"; foreach ($vowelCounts as $vowel => $count) { echo "<li>$vowel: $count</li>"; } echo "</ul>"; } ?> </body> </html>
Copy Clear