You need to process each byte in a string individually.
Use the for loop to iterate through each byte in the string.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php $string = "This weekend, I'm going shopping for a new clothe."; $vowels = 0; for ($i = 0, $j = strlen($string); $i < $j; $i++) { // find the occurence of a byte if (strstr('aeiouAEIOU', $string[$i])) { $vowels++; } } echo $string, "<br />"; echo "Number of vowels found: $vowels<br />"; ?> </p> </body> </html> |