0

I'm having a problem with a code to display the vowels used in a string for example: "I LOVE YOU" the code will display "The vowels used are: e i o u"
Any help?
I'm supposed to use loops such as foreach, for, do-while, etc. and arrays..

5
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by skraps
0
echo preg_replace('~[^aeiou]~i', '', 'i love you')

should remove all non vowel character. I haven't tested it yet but I might be start.

1

Don't think he wants to remove them, just identify them.

Do you want to include accented characters like â? If so, should they be listed separately or slugified (â,à etc = a, ô etc = o).

Are the vowels supposed to be case-sensitive?

$text = 'Hi AlaôyÖ!  know the way to K\'ôêìlp';
$text = strtolower(preg_replace('~[^-\w]+~', '', iconv('utf-8', 'us-ascii//TRANSLIT', $text)));
$check = array('a','e','i','o','u');
foreach($check as $chk){
	if(strpos($text,$chk) !== false){
		$ans[] = $chk;	
	}
}
if(isset($ans)){
	$comment = "Vowels in this string: " . implode(", ",$ans); 
}else{
	$comment = "No vowels were found in this string";	
}
echo $comment;

Edited by diafol: n/a

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.