A simple bit of code not counting correctly.
Posted: Wed Aug 30, 2006 4:31 pm
I have written this snippet of code for counting vowels in a string.
But it always always returns $A as 1. Even if there are no vowels in the string. Any ideas what's going on here?
Regards, Stephen
Code: Select all
unset($A);
unset($E);
unset($I);
unset($O);
unset($U);
$text = $_REQUEST["text"];
for ($i = 0; $i < strlen($text); $i++) {
if ($text[$i] = "a" or "A") {
$A += 1;
}
else if ($text[$i] = "e" or "E") {
$E += 1;
}
else if ($text[$i] = "i" or "I") {
$I += 1;
}
else if ($text[$i] = "o" or "O") {
$O += 1;
}
else if ($text[$i] = "u" or "U") {
$U += 1;
}
}
echo "<b>A:</b> $A<br>";
echo "<b>E:</b> $E<br>";
echo "<b>I:</b> $I<br>";
echo "<b>O:</b> $O<br>";
echo "<b>U:</b> $U<br>";Regards, Stephen