PHP script to determine if letter Y is a consonant or vowel

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Also with the new rules that wpas included this solutions logic would need to be changed.
  • alemao_brazil
  • Newbie
  • Newbie
  • alemao_brazil
  • Posts: 8

Post 3+ Months Ago

Well some considerations:
1- the codes I suggested were not to be used all together, I explain, when I said "to force y as the first letter use ^", I was giving an option not saying to use in the code. They were not to be used in sequence.
2- I wrote that code considering only the examples shown in the topic first post. The chalenge was to define when y was a vowel or consonant in a word containing ONLY ONE y, so, Sydney was not considered when I offered my solution.
3- Tell me in Sydney what would be the correct answer for the two y and I will modify the code. (Is it vowel and consonant?)
  • alemao_brazil
  • Newbie
  • Newbie
  • alemao_brazil
  • Posts: 8

Post 3+ Months Ago

As English is not my native language, I have difficulty in determining when y is vowel or consonant, sometimes I get confused.
BUT the clue is there: use preg_match is the most intelligent way to do it.
Here is one example to give 3 answers: 'consonant', 'vowel' and 'both':
PHP Code: [ Select ]
function check_y($word) {
   
   // Make an array to return info
   $return_array = array();
   
   # Credits: Sergio Abreu
 
   if( preg_match( "/y[aeiou]/i", $word)){
      $return_array[$word] = 'consonant';
   }
 
 
  if( preg_match( "/([b-z]y)|([aeiou]y)/i", $word)){
      $return_array[$word] = $return_array[$word] == 'consonant' ? 'both' :  'vowel';
   }
   
 
 
     
   // Return the return array
   return $return_array;
   
}
 
  1. function check_y($word) {
  2.    
  3.    // Make an array to return info
  4.    $return_array = array();
  5.    
  6.    # Credits: Sergio Abreu
  7.  
  8.    if( preg_match( "/y[aeiou]/i", $word)){
  9.       $return_array[$word] = 'consonant';
  10.    }
  11.  
  12.  
  13.   if( preg_match( "/([b-z]y)|([aeiou]y)/i", $word)){
  14.       $return_array[$word] = $return_array[$word] == 'consonant' ? 'both' :  'vowel';
  15.    }
  16.    
  17.  
  18.  
  19.      
  20.    // Return the return array
  21.    return $return_array;
  22.    
  23. }
  24.  

Post Information

  • Total Posts in this topic: 33 posts
  • Users browsing this forum: No registered users and 76 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.