Member Avatar for rayrenz

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..

Post your code, so I can help you to find the problem

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.

Member Avatar for diafol

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;
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.