February 27, 2013

Split words starting with vowels and consonants to arrays

Question by user2116493

i have to make a script in PHP. First in splits the sentence by spaces and adds to array. Then it splits the words from array by the starting letter. If it starts with vowel, it goes into one array and if it starts with consonant, it goes to other arrray. Then it prints the words with the both arrays and shows the number of letters in the word by every word.
Allowed functsions are explode, strlen, in_array.
Thank you.

Answer by Starx

You can start by using explode() function.

$sentence = "Your long long sentence";
$explodeIntoWords = explode(" ", $sentence); //You can specify the sentence to be split based on words.

//Now you can loop through this array and compare them if they are vowels or consonants 
foreach($explodeIntoWords as $value) {
   // Analyse $value 
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!