0
<html>
<title>
consonants vowels and numbers
</title>
<body bgcolor=red text=white><form method=post><font size=15>
Enter a word(s):<input type=text name='phrase'></br>
<input type=submit value=generate></br>
<?php
$vowel;
$conso;
$nums;
switch($_POST['phrase']){
case'a':
case'A':
case'E':
Case'e':
Case'I':
case'i':
case'O':
case'o':
case'U':
case'u':
$vowel+=1;
break;
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'8':
case'9':
$nums+=1;
break;
default:
$conso+=1;
break;
}

echo"Vowels:",$vowel;
echo"</br>";
echo"Consonants:",$conso;
echo"</br>";
echo"Numbers:",$nums;
echo"</br>";
?>

<input type=reset value=reset>
</font>
</form>
</body>
</html>

can someone tell me how to do it on full string type???
I need to count consonants the vowels and the numbers disregarding the spaces and special characters

Edited by Ezzaral: Fixed code tags.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by diafol
0

You can access single characters within a string by using square brackets like the string is an array.

Using this method you could use code like this:

$inputString = $_POST['phrase'];
for($i = 0; $i < strlen($inputString); $i++)
{
$stringChar = $inputString[$i];
switch($stringChar)
{
//your switch statement code here
}
}
1

You may find using regex in the switch area may be more efficient than multiple case statements.

vowels = [AEIOUaeiou], etc.

Votes + Comments
Thank you for teaching me something about switch statements that I didn't know :) - RKeast
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.