954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Search the Vowels Used

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

rayrenz
Newbie Poster
4 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

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

niranga
Junior Poster
163 posts since Apr 2010
Reputation Points: 21
Solved Threads: 21
 
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.

qazplm114477
Junior Poster
193 posts since Apr 2010
Reputation Points: 24
Solved Threads: 37
 

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;
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
preg_match_all('/[aeiou]+/i', 'i love you', $arr, PREG_PATTERN_ORDER);


heres a cool tester.
http://www.solmetra.com/scripts/regex/index.php

skraps
Light Poster
Banned
42 posts since Nov 2011
Reputation Points: 1
Solved Threads: 3
Infraction Points: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: