<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

Member Avatar for Rkeast

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
}
}
Member Avatar for diafol

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

vowels = [AEIOUaeiou], etc.

commented: Thank you for teaching me something about switch statements that I didn't know :) - RKeast +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.