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


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
If i change the vowel loop to
Almost all cases work except Yvonne gets messed up again
PHP Code: [ Select ]
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
if($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') || strpos($word_array[$i], 'y') == 0) {
echo $word_array[$i] . ' in If';
// Y is after vowel so it is a constant
$return_array[$word][$i] = 'consonant<br>';
} /*else if(strpos($word_array[$i], 'y') + 1 == $vowels_check['vowels'][$j]['pos']) {
echo $word_array[$i] . ' in else If<br>';
// Y is before vowel so it is a Vowel
$return_array[$word][$i] = 'vowel';
}*/ else {
echo $word_array[$i] . ' in else<br><br>';
// Y is before vowel so it is a Vowel
$return_array[$word][$i] = 'vowel';
}
}
}
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
if($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') || strpos($word_array[$i], 'y') == 0) {
echo $word_array[$i] . ' in If';
// Y is after vowel so it is a constant
$return_array[$word][$i] = 'consonant<br>';
} /*else if(strpos($word_array[$i], 'y') + 1 == $vowels_check['vowels'][$j]['pos']) {
echo $word_array[$i] . ' in else If<br>';
// Y is before vowel so it is a Vowel
$return_array[$word][$i] = 'vowel';
}*/ else {
echo $word_array[$i] . ' in else<br><br>';
// Y is before vowel so it is a Vowel
$return_array[$word][$i] = 'vowel';
}
}
}
- // Loop Vowels found
- for($j=0; $j<count($vowels_check['vowels']); $j++) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- // Check position of vowel
- if($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') || strpos($word_array[$i], 'y') == 0) {
- echo $word_array[$i] . ' in If';
- // Y is after vowel so it is a constant
- $return_array[$word][$i] = 'consonant<br>';
- } /*else if(strpos($word_array[$i], 'y') + 1 == $vowels_check['vowels'][$j]['pos']) {
- echo $word_array[$i] . ' in else If<br>';
- // Y is before vowel so it is a Vowel
- $return_array[$word][$i] = 'vowel';
- }*/ else {
- echo $word_array[$i] . ' in else<br><br>';
- // Y is before vowel so it is a Vowel
- $return_array[$word][$i] = 'vowel';
- }
- }
- }
Almost all cases work except Yvonne gets messed up again
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
December 21st, 2012, 8:20 pm
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
Updated check y function
PHP Code: [ Select ]
function check_y($word) {
// Start the class
$syllable = new Syllable('en-us');
// Make th word lower case
$word = strtolower($word);
// Check for Y
if(strpos($word, 'y') === false) {
// No Y found
return 'No Y Found';
}
// Make an array to return info
$return_array = array();
// Breakword into syllables
$syllable->setTreshold(Syllable::TRESHOLD_MOST);
$word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
// Loop the word array
for($i=0; $i<count($word_array); $i++) {
// Check for vowels
$vowels_check = vowel_check($word_array[$i]);
// Check for no vowels
if(!$vowels_check['found']) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// No Vowels found so Y is a vowel
$return_array[$word][$i] = 'vowel';
}
} else {
//echo $word_array[$i] . ' ';
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
if($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') || strpos($word_array[$i], 'y') == 0) {
// Y is after vowel so it is a constant
$return_array[$word][$i] = 'consonant<br>';
} else {
// Y is before vowel so it is a Vowel
$return_array[$word][$i] = 'vowel';
}
}
}
}
}
// Return the return array
return $return_array;
}
// Start the class
$syllable = new Syllable('en-us');
// Make th word lower case
$word = strtolower($word);
// Check for Y
if(strpos($word, 'y') === false) {
// No Y found
return 'No Y Found';
}
// Make an array to return info
$return_array = array();
// Breakword into syllables
$syllable->setTreshold(Syllable::TRESHOLD_MOST);
$word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
// Loop the word array
for($i=0; $i<count($word_array); $i++) {
// Check for vowels
$vowels_check = vowel_check($word_array[$i]);
// Check for no vowels
if(!$vowels_check['found']) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// No Vowels found so Y is a vowel
$return_array[$word][$i] = 'vowel';
}
} else {
//echo $word_array[$i] . ' ';
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
if($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') || strpos($word_array[$i], 'y') == 0) {
// Y is after vowel so it is a constant
$return_array[$word][$i] = 'consonant<br>';
} else {
// Y is before vowel so it is a Vowel
$return_array[$word][$i] = 'vowel';
}
}
}
}
}
// Return the return array
return $return_array;
}
- function check_y($word) {
- // Start the class
- $syllable = new Syllable('en-us');
- // Make th word lower case
- $word = strtolower($word);
- // Check for Y
- if(strpos($word, 'y') === false) {
- // No Y found
- return 'No Y Found';
- }
- // Make an array to return info
- $return_array = array();
- // Breakword into syllables
- $syllable->setTreshold(Syllable::TRESHOLD_MOST);
- $word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
- // Loop the word array
- for($i=0; $i<count($word_array); $i++) {
- // Check for vowels
- $vowels_check = vowel_check($word_array[$i]);
- // Check for no vowels
- if(!$vowels_check['found']) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- // No Vowels found so Y is a vowel
- $return_array[$word][$i] = 'vowel';
- }
- } else {
- //echo $word_array[$i] . ' ';
- // Loop Vowels found
- for($j=0; $j<count($vowels_check['vowels']); $j++) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- // Check position of vowel
- if($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') || strpos($word_array[$i], 'y') == 0) {
- // Y is after vowel so it is a constant
- $return_array[$word][$i] = 'consonant<br>';
- } else {
- // Y is before vowel so it is a Vowel
- $return_array[$word][$i] = 'vowel';
- }
- }
- }
- }
- }
- // Return the return array
- return $return_array;
- }
- wpas
- Graduate


- Joined: Jul 12, 2010
- Posts: 214
- Loc: Canada
- Status: Offline
The more I dig into this, the more differing opinions I get, even why I contacted some english teaches.
To try an narrow this done I have come up with 2 things that I was given that I will use as a basis for testing.
Rule 1
If you replace the letter y with the sound /j/ and the word sounds almost the same then it is a consonant, even though you would appear to have an accent.
e.g., yell would almost sound the same with /j/ so y is consonant
day would not sound the same with /j/, so y is a vowel.
Rule 2
Y is a consonant when it appears at the start of a syllable where there is another vowel (yam, yet).
Rule 3
If there are no vowels in the word then y is a vowel such as gym.
If it takes the place of a vowel, then y is a vowel such as system.
I don't know how correct I am, but this is where I would like to start.
Based on the above I created the following for testing:
For Vowels:
check_test('anyone baby betty boy bryan by bycycle candy cry cycle day dry dynamic elly fly flying goodbye gym happy hairy hymn joy lynn many mary my mystery myth play pony pry psycho quickly rye rhyme rhythm say shy sky sly spy soy symbol syringe tiny trendy try very vinyl why wyatt yvonne')
For consonants:
check_test('hey key kyle lloyd oyster player yacht yahoo yale yam yarn yield yell yellow yeltsin yes yesterday yet yoda yogurt yoke yolanda you young your yvette royce')
For both:
check_test('sydney')
If anyone has any further suggestions I would be very happy to hear from you.
To try an narrow this done I have come up with 2 things that I was given that I will use as a basis for testing.
Rule 1
If you replace the letter y with the sound /j/ and the word sounds almost the same then it is a consonant, even though you would appear to have an accent.
e.g., yell would almost sound the same with /j/ so y is consonant
day would not sound the same with /j/, so y is a vowel.
Rule 2
Y is a consonant when it appears at the start of a syllable where there is another vowel (yam, yet).
Rule 3
If there are no vowels in the word then y is a vowel such as gym.
If it takes the place of a vowel, then y is a vowel such as system.
I don't know how correct I am, but this is where I would like to start.
Based on the above I created the following for testing:
For Vowels:
check_test('anyone baby betty boy bryan by bycycle candy cry cycle day dry dynamic elly fly flying goodbye gym happy hairy hymn joy lynn many mary my mystery myth play pony pry psycho quickly rye rhyme rhythm say shy sky sly spy soy symbol syringe tiny trendy try very vinyl why wyatt yvonne')
For consonants:
check_test('hey key kyle lloyd oyster player yacht yahoo yale yam yarn yield yell yellow yeltsin yes yesterday yet yoda yogurt yoke yolanda you young your yvette royce')
For both:
check_test('sydney')
If anyone has any further suggestions I would be very happy to hear from you.
http://www.schembrionics.com
The Ultimate Solutions Center
The Ultimate Solutions Center
- wpas
- Graduate


- Joined: Jul 12, 2010
- Posts: 214
- Loc: Canada
- Status: Offline
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
Rule 1 is the rule that is going to be the most difficult to get correct.
is there a correlation to the vowel to the y that would constantly be the same
Example
oy ay and uy being vowels ... boy day buy
and ey being consonants ... hey
If this is the case this should make things a bit easier
is there a correlation to the vowel to the y that would constantly be the same
Example
oy ay and uy being vowels ... boy day buy
and ey being consonants ... hey
If this is the case this should make things a bit easier
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
Here is updated code to test with
PHP Code: [ Select ]
<?php
// Include the class
require_once(dirname(__FILE__) . '/Syllable.php');
function vowel_check($word) {
// Setup an array of vowels
$vowels = array('a', 'e', 'i', 'o', 'u');
// Make an return array
$return_array = array("found" => false);
// Make a counter
$ii = 0;
// Loop the letters
for($i=0; $i<strlen($word); $i++) {
// Check for vowels
if(in_array($word[$i], $vowels)) {
// Set found to true
$return_array['found'] = true;
// Build the info
$return_array['vowels'][$ii]['letter'] = $word[$i];
$return_array['vowels'][$ii]['pos'] = strpos($word, $word[$i]);
// Add to counter
$ii++;
}
}
// Return $return_array
return $return_array;
}
function check_y($word) {
// Start the class
$syllable = new Syllable('en-us');
// Make th word lower case
$word = strtolower($word);
// Check for Y
if(strpos($word, 'y') === false) {
// No Y found
return 'No Y Found';
}
// Make an array to return info
$return_array = array();
// Breakword into syllables
$syllable->setTreshold(Syllable::TRESHOLD_MOST);
$word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
// Loop the word array
for($i=0; $i<count($word_array); $i++) {
// Check for vowels
$vowels_check = vowel_check($word_array[$i]);
// Check for no vowels
if(!$vowels_check['found']) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
if(strpos($word_array[$i], 'y') == 0) {
// No Vowels and y is the first letter of the word
$return_array[$word][$i] = 'consonant';
} else {
// No Vowels found so Y is a vowel
$return_array[$word][$i] = 'vowel';
}
}
} else {
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
switch(true) {
// Vowel before and vowel being o a or u
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'a'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'o'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'u'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Vowel before and vowel being e or i
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'e'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'i'):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
// YV fix the syllable class does not break the yv apart into the correct syllable grouping so this is a fix to
// counter act this issue
case (strtolower($word_array[$i][strpos($word_array[$i], 'y')+1]) == 'v'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Y is first letter
case (strpos($word_array[$i], 'y') == 0):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
}
}
}
}
}
// Return the return array
return $return_array;
}
echo '<pre>';
var_dump(check_text('boy Sydney Billy Sylvia Missy Kyle Blythe Sylvester Katy Kay Yeltsin May Kuykendahl yes yam yell yellow yogurt yale gym my cycle baby hairy sky Lynn Yvonne Mary Betty Elly Bryan Maloney Murray Wyatt'));
//var_dump(check_text('anyone baby betty boy bryan by bycycle candy cry cycle day dry dynamic elly fly flying goodbye gym happy hairy hymn joy lynn many mary my mystery myth play pony pry psycho quickly rye rhyme rhythm say shy sky sly spy soy symbol syringe tiny trendy try very vinyl why wyatt yvonne yvette'));
//var_dump(check_text('hey key kyle lloyd oyster player yacht yahoo yale yam yarn yield yell yellow yeltsin yes yesterday yet yoda yogurt yoke yolanda you young your royce'));
//check_text('Sylvia');
echo '</pre>';
function check_text($text) {
// Make sure we have text
if(empty($text)) {
// Kick back
return false;
}
// Break text into words
$text_array = explode(' ', $text);
// Make an array to return info
$return_array = array();
// Loop Text
for($i=0; $i<count($text_array); $i++) {
// Check the word
$temp_array = check_y($text_array[$i]);
if(!empty($temp_array)) {
// Add to the return array
$return_array[] = $temp_array;
}
}
// Return the array
return $return_array;
}
?>
// Include the class
require_once(dirname(__FILE__) . '/Syllable.php');
function vowel_check($word) {
// Setup an array of vowels
$vowels = array('a', 'e', 'i', 'o', 'u');
// Make an return array
$return_array = array("found" => false);
// Make a counter
$ii = 0;
// Loop the letters
for($i=0; $i<strlen($word); $i++) {
// Check for vowels
if(in_array($word[$i], $vowels)) {
// Set found to true
$return_array['found'] = true;
// Build the info
$return_array['vowels'][$ii]['letter'] = $word[$i];
$return_array['vowels'][$ii]['pos'] = strpos($word, $word[$i]);
// Add to counter
$ii++;
}
}
// Return $return_array
return $return_array;
}
function check_y($word) {
// Start the class
$syllable = new Syllable('en-us');
// Make th word lower case
$word = strtolower($word);
// Check for Y
if(strpos($word, 'y') === false) {
// No Y found
return 'No Y Found';
}
// Make an array to return info
$return_array = array();
// Breakword into syllables
$syllable->setTreshold(Syllable::TRESHOLD_MOST);
$word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
// Loop the word array
for($i=0; $i<count($word_array); $i++) {
// Check for vowels
$vowels_check = vowel_check($word_array[$i]);
// Check for no vowels
if(!$vowels_check['found']) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
if(strpos($word_array[$i], 'y') == 0) {
// No Vowels and y is the first letter of the word
$return_array[$word][$i] = 'consonant';
} else {
// No Vowels found so Y is a vowel
$return_array[$word][$i] = 'vowel';
}
}
} else {
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
switch(true) {
// Vowel before and vowel being o a or u
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'a'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'o'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'u'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Vowel before and vowel being e or i
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'e'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'i'):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
// YV fix the syllable class does not break the yv apart into the correct syllable grouping so this is a fix to
// counter act this issue
case (strtolower($word_array[$i][strpos($word_array[$i], 'y')+1]) == 'v'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Y is first letter
case (strpos($word_array[$i], 'y') == 0):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
}
}
}
}
}
// Return the return array
return $return_array;
}
echo '<pre>';
var_dump(check_text('boy Sydney Billy Sylvia Missy Kyle Blythe Sylvester Katy Kay Yeltsin May Kuykendahl yes yam yell yellow yogurt yale gym my cycle baby hairy sky Lynn Yvonne Mary Betty Elly Bryan Maloney Murray Wyatt'));
//var_dump(check_text('anyone baby betty boy bryan by bycycle candy cry cycle day dry dynamic elly fly flying goodbye gym happy hairy hymn joy lynn many mary my mystery myth play pony pry psycho quickly rye rhyme rhythm say shy sky sly spy soy symbol syringe tiny trendy try very vinyl why wyatt yvonne yvette'));
//var_dump(check_text('hey key kyle lloyd oyster player yacht yahoo yale yam yarn yield yell yellow yeltsin yes yesterday yet yoda yogurt yoke yolanda you young your royce'));
//check_text('Sylvia');
echo '</pre>';
function check_text($text) {
// Make sure we have text
if(empty($text)) {
// Kick back
return false;
}
// Break text into words
$text_array = explode(' ', $text);
// Make an array to return info
$return_array = array();
// Loop Text
for($i=0; $i<count($text_array); $i++) {
// Check the word
$temp_array = check_y($text_array[$i]);
if(!empty($temp_array)) {
// Add to the return array
$return_array[] = $temp_array;
}
}
// Return the array
return $return_array;
}
?>
- <?php
- // Include the class
- require_once(dirname(__FILE__) . '/Syllable.php');
- function vowel_check($word) {
- // Setup an array of vowels
- $vowels = array('a', 'e', 'i', 'o', 'u');
- // Make an return array
- $return_array = array("found" => false);
- // Make a counter
- $ii = 0;
- // Loop the letters
- for($i=0; $i<strlen($word); $i++) {
- // Check for vowels
- if(in_array($word[$i], $vowels)) {
- // Set found to true
- $return_array['found'] = true;
- // Build the info
- $return_array['vowels'][$ii]['letter'] = $word[$i];
- $return_array['vowels'][$ii]['pos'] = strpos($word, $word[$i]);
- // Add to counter
- $ii++;
- }
- }
- // Return $return_array
- return $return_array;
- }
- function check_y($word) {
- // Start the class
- $syllable = new Syllable('en-us');
- // Make th word lower case
- $word = strtolower($word);
- // Check for Y
- if(strpos($word, 'y') === false) {
- // No Y found
- return 'No Y Found';
- }
- // Make an array to return info
- $return_array = array();
- // Breakword into syllables
- $syllable->setTreshold(Syllable::TRESHOLD_MOST);
- $word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
- // Loop the word array
- for($i=0; $i<count($word_array); $i++) {
- // Check for vowels
- $vowels_check = vowel_check($word_array[$i]);
- // Check for no vowels
- if(!$vowels_check['found']) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- if(strpos($word_array[$i], 'y') == 0) {
- // No Vowels and y is the first letter of the word
- $return_array[$word][$i] = 'consonant';
- } else {
- // No Vowels found so Y is a vowel
- $return_array[$word][$i] = 'vowel';
- }
- }
- } else {
- // Loop Vowels found
- for($j=0; $j<count($vowels_check['vowels']); $j++) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- // Check position of vowel
- switch(true) {
- // Vowel before and vowel being o a or u
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'a'):
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'o'):
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'u'):
- // Y is s vowel
- $return_array[$word][$i] = 'vowel';
- // Kickout
- break;
- // Vowel before and vowel being e or i
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'e'):
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'i'):
- // Y is s consonant
- $return_array[$word][$i] = 'consonant';
- // Kickout
- break;
- // YV fix the syllable class does not break the yv apart into the correct syllable grouping so this is a fix to
- // counter act this issue
- case (strtolower($word_array[$i][strpos($word_array[$i], 'y')+1]) == 'v'):
- // Y is s vowel
- $return_array[$word][$i] = 'vowel';
- // Kickout
- break;
- // Y is first letter
- case (strpos($word_array[$i], 'y') == 0):
- // Y is s consonant
- $return_array[$word][$i] = 'consonant';
- // Kickout
- break;
- }
- }
- }
- }
- }
- // Return the return array
- return $return_array;
- }
- echo '<pre>';
- var_dump(check_text('boy Sydney Billy Sylvia Missy Kyle Blythe Sylvester Katy Kay Yeltsin May Kuykendahl yes yam yell yellow yogurt yale gym my cycle baby hairy sky Lynn Yvonne Mary Betty Elly Bryan Maloney Murray Wyatt'));
- //var_dump(check_text('anyone baby betty boy bryan by bycycle candy cry cycle day dry dynamic elly fly flying goodbye gym happy hairy hymn joy lynn many mary my mystery myth play pony pry psycho quickly rye rhyme rhythm say shy sky sly spy soy symbol syringe tiny trendy try very vinyl why wyatt yvonne yvette'));
- //var_dump(check_text('hey key kyle lloyd oyster player yacht yahoo yale yam yarn yield yell yellow yeltsin yes yesterday yet yoda yogurt yoke yolanda you young your royce'));
- //check_text('Sylvia');
- echo '</pre>';
- function check_text($text) {
- // Make sure we have text
- if(empty($text)) {
- // Kick back
- return false;
- }
- // Break text into words
- $text_array = explode(' ', $text);
- // Make an array to return info
- $return_array = array();
- // Loop Text
- for($i=0; $i<count($text_array); $i++) {
- // Check the word
- $temp_array = check_y($text_array[$i]);
- if(!empty($temp_array)) {
- // Add to the return array
- $return_array[] = $temp_array;
- }
- }
- // Return the array
- return $return_array;
- }
- ?>
- wpas
- Graduate


- Joined: Jul 12, 2010
- Posts: 214
- Loc: Canada
- Status: Offline
Hey ScottG
After going over everything carefully, I had been wrong in a few areas. After hours of investigating, I believe the following is probably the most correct for the letter y.
1. words with "oy" the letter y is a vowel
e.g. boy, joy, toy, roy
2. words with ay, ey and uy the letter y is a consonant
e.g., pay, say, day, key, buy, mayor, murray, maloney
3. Y is a consonant when it appears at the start of a syllable where there is another vowel (yam, yet, yolanda, yoda), creating the "yuh" sound. In the word player, the "yuh" sound is heard, so y is a consonant.
4. If there are no vowels in the word then y is a vowel such as gym, Lynn, Yvonne, Yvette, Mary, Betty, Elly, and Bryan.
If it takes the place of a vowel, then y is a vowel such as system, Bryan and Wyatt.
5. Other examples
-In Billy, Sylvia, Missy, Kyle, Blythe, Sylvester, and Katy, the Y is a vowel
-In gym, my, cycle, baby, hairy, sky the y is a vowel
-In Kay, Yeltsin, May, and Kuykendahl, the Y is a consonant.
-In Sydney, the first Y is a vowel, the second Y is a consonant.
-In yes, yam, yell, yellow, yogurt, yale the y is a consonant.
After going over everything carefully, I had been wrong in a few areas. After hours of investigating, I believe the following is probably the most correct for the letter y.
1. words with "oy" the letter y is a vowel
e.g. boy, joy, toy, roy
2. words with ay, ey and uy the letter y is a consonant
e.g., pay, say, day, key, buy, mayor, murray, maloney
3. Y is a consonant when it appears at the start of a syllable where there is another vowel (yam, yet, yolanda, yoda), creating the "yuh" sound. In the word player, the "yuh" sound is heard, so y is a consonant.
4. If there are no vowels in the word then y is a vowel such as gym, Lynn, Yvonne, Yvette, Mary, Betty, Elly, and Bryan.
If it takes the place of a vowel, then y is a vowel such as system, Bryan and Wyatt.
5. Other examples
-In Billy, Sylvia, Missy, Kyle, Blythe, Sylvester, and Katy, the Y is a vowel
-In gym, my, cycle, baby, hairy, sky the y is a vowel
-In Kay, Yeltsin, May, and Kuykendahl, the Y is a consonant.
-In Sydney, the first Y is a vowel, the second Y is a consonant.
-In yes, yam, yell, yellow, yogurt, yale the y is a consonant.
http://www.schembrionics.com
The Ultimate Solutions Center
The Ultimate Solutions Center
- wpas
- Graduate


- Joined: Jul 12, 2010
- Posts: 214
- Loc: Canada
- Status: Offline
I ran your new script and based on new rules in my previous post the following needs changing:
kay: y stated as vowel but should be consonant
may: y stated as vowel but should be consonant
kuykendahl: y stated as vowel but should be consonant
murray: y stated as vowel but should be consonant
I investigated these words further and they were indeed all specified as y being a consonant.
kay: y stated as vowel but should be consonant
may: y stated as vowel but should be consonant
kuykendahl: y stated as vowel but should be consonant
murray: y stated as vowel but should be consonant
I investigated these words further and they were indeed all specified as y being a consonant.
http://www.schembrionics.com
The Ultimate Solutions Center
The Ultimate Solutions Center
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
ok So here is the altered check y function based on the new rules set
Passed all examples you provided
Passed all examples you provided
PHP Code: [ Select ]
function check_y($word) {
// Start the class
$syllable = new Syllable('en-us');
// Make th word lower case
$word = strtolower($word);
// Check for Y
if(strpos($word, 'y') === false) {
// No Y found
return 'No Y Found';
}
// Make an array to return info
$return_array = array();
// Breakword into syllables
$syllable->setTreshold(Syllable::TRESHOLD_MOST);
$word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
// Loop the word array
for($i=0; $i<count($word_array); $i++) {
// Check for vowels
$vowels_check = vowel_check($word_array[$i]);
// Check for no vowels
if(!$vowels_check['found']) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
if(strpos($word_array[$i], 'y') == 0) {
// No Vowels and y is the first letter of the word
$return_array[$word][$i] = 'consonant';
} else {
// No Vowels found so Y is a vowel
$return_array[$word][$i] = 'vowel';
}
}
} else {
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
switch(true) {
// Vowel before and vowel being o
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'o'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Vowel before and vowel being a, e, i or u
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'a'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'e'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'i'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'u'):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
// YV fix the sylible class does not break the yv apart into the correct sylible grouping so this is a fix to
// counter act this issue
case (strtolower($word_array[$i][strpos($word_array[$i], 'y')+1]) == 'v'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Y is first letter
case (strpos($word_array[$i], 'y') == 0):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
// Y not next two vowels
default:
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
}
}
}
}
}
// Return the return array
return $return_array;
}
// Start the class
$syllable = new Syllable('en-us');
// Make th word lower case
$word = strtolower($word);
// Check for Y
if(strpos($word, 'y') === false) {
// No Y found
return 'No Y Found';
}
// Make an array to return info
$return_array = array();
// Breakword into syllables
$syllable->setTreshold(Syllable::TRESHOLD_MOST);
$word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
// Loop the word array
for($i=0; $i<count($word_array); $i++) {
// Check for vowels
$vowels_check = vowel_check($word_array[$i]);
// Check for no vowels
if(!$vowels_check['found']) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
if(strpos($word_array[$i], 'y') == 0) {
// No Vowels and y is the first letter of the word
$return_array[$word][$i] = 'consonant';
} else {
// No Vowels found so Y is a vowel
$return_array[$word][$i] = 'vowel';
}
}
} else {
// Loop Vowels found
for($j=0; $j<count($vowels_check['vowels']); $j++) {
// Check for Y
if(strpos($word_array[$i], 'y') !== false) {
// Check position of vowel
switch(true) {
// Vowel before and vowel being o
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'o'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Vowel before and vowel being a, e, i or u
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'a'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'e'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'i'):
case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'u'):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
// YV fix the sylible class does not break the yv apart into the correct sylible grouping so this is a fix to
// counter act this issue
case (strtolower($word_array[$i][strpos($word_array[$i], 'y')+1]) == 'v'):
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
// Y is first letter
case (strpos($word_array[$i], 'y') == 0):
// Y is s consonant
$return_array[$word][$i] = 'consonant';
// Kickout
break;
// Y not next two vowels
default:
// Y is s vowel
$return_array[$word][$i] = 'vowel';
// Kickout
break;
}
}
}
}
}
// Return the return array
return $return_array;
}
- function check_y($word) {
- // Start the class
- $syllable = new Syllable('en-us');
- // Make th word lower case
- $word = strtolower($word);
- // Check for Y
- if(strpos($word, 'y') === false) {
- // No Y found
- return 'No Y Found';
- }
- // Make an array to return info
- $return_array = array();
- // Breakword into syllables
- $syllable->setTreshold(Syllable::TRESHOLD_MOST);
- $word_array = explode('­', utf8_encode($syllable->hyphenateText($word)));
- // Loop the word array
- for($i=0; $i<count($word_array); $i++) {
- // Check for vowels
- $vowels_check = vowel_check($word_array[$i]);
- // Check for no vowels
- if(!$vowels_check['found']) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- if(strpos($word_array[$i], 'y') == 0) {
- // No Vowels and y is the first letter of the word
- $return_array[$word][$i] = 'consonant';
- } else {
- // No Vowels found so Y is a vowel
- $return_array[$word][$i] = 'vowel';
- }
- }
- } else {
- // Loop Vowels found
- for($j=0; $j<count($vowels_check['vowels']); $j++) {
- // Check for Y
- if(strpos($word_array[$i], 'y') !== false) {
- // Check position of vowel
- switch(true) {
- // Vowel before and vowel being o
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'o'):
- // Y is s vowel
- $return_array[$word][$i] = 'vowel';
- // Kickout
- break;
- // Vowel before and vowel being a, e, i or u
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'a'):
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'e'):
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'i'):
- case ($vowels_check['vowels'][$j]['pos'] + 1 == strpos($word_array[$i], 'y') && $vowels_check['vowels'][$j]['letter'] == 'u'):
- // Y is s consonant
- $return_array[$word][$i] = 'consonant';
- // Kickout
- break;
- // YV fix the sylible class does not break the yv apart into the correct sylible grouping so this is a fix to
- // counter act this issue
- case (strtolower($word_array[$i][strpos($word_array[$i], 'y')+1]) == 'v'):
- // Y is s vowel
- $return_array[$word][$i] = 'vowel';
- // Kickout
- break;
- // Y is first letter
- case (strpos($word_array[$i], 'y') == 0):
- // Y is s consonant
- $return_array[$word][$i] = 'consonant';
- // Kickout
- break;
- // Y not next two vowels
- default:
- // Y is s vowel
- $return_array[$word][$i] = 'vowel';
- // Kickout
- break;
- }
- }
- }
- }
- }
- // Return the return array
- return $return_array;
- }
- wpas
- Graduate


- Joined: Jul 12, 2010
- Posts: 214
- Loc: Canada
- Status: Offline
I figured if I dug enough, I would eventually find a general consensus on how to determine when the letter Y was a vowel or a consonant. Fortunately for me, it agreed with the rules I plan to use.
The following is what I found:
If a syllable begins with Y, and the next letter represents a vowel, then Y almost certainly represents a consonant. In “yo” for example, Y represent a consonant.
If a syllable begins with Y and the next letter represents a consonant, then the Y represents a vowel such as, Yvonne, Yvette, Yves, yttrium.
In words like “rhythm,” Y represents a vowel, specifically the short I sound. However, in a word such as the name “Reynold,” it doesn’t make sense to say that Y represents a vowel. It’s the two-letter combination E-Y that represents a vowel so y here is a consonant.
In one-syllable words such as “by” and “fly,” Y represents the vowel commonly known as long I.
In longer words such as “sorry” and “friendly,” it represents the vowel of long E (or maybe short I again—speakers vary).
In words like “hey” or “day, the letter combinations of E-Y and A-Y together represent the long A sound in these words so y here is a consonant.
For the Y at the end of a word like “boy”, “oy” is a diphthong, consisting of an O-like vowel followed by long E or short I.
There is debate among phoneticians on wether y is a vowel or consonant. They don’t all agree on this.
In my case I have chosen to make it a vowel.
So then, Y gets to represent a vowel in many words. It represents short I in words like “gym,” and either short I or long E in words like “happy.” It represents a diphthong in words like “by.”
The following is what I found:
If a syllable begins with Y, and the next letter represents a vowel, then Y almost certainly represents a consonant. In “yo” for example, Y represent a consonant.
If a syllable begins with Y and the next letter represents a consonant, then the Y represents a vowel such as, Yvonne, Yvette, Yves, yttrium.
In words like “rhythm,” Y represents a vowel, specifically the short I sound. However, in a word such as the name “Reynold,” it doesn’t make sense to say that Y represents a vowel. It’s the two-letter combination E-Y that represents a vowel so y here is a consonant.
In one-syllable words such as “by” and “fly,” Y represents the vowel commonly known as long I.
In longer words such as “sorry” and “friendly,” it represents the vowel of long E (or maybe short I again—speakers vary).
In words like “hey” or “day, the letter combinations of E-Y and A-Y together represent the long A sound in these words so y here is a consonant.
For the Y at the end of a word like “boy”, “oy” is a diphthong, consisting of an O-like vowel followed by long E or short I.
There is debate among phoneticians on wether y is a vowel or consonant. They don’t all agree on this.
In my case I have chosen to make it a vowel.
So then, Y gets to represent a vowel in many words. It represents short I in words like “gym,” and either short I or long E in words like “happy.” It represents a diphthong in words like “by.”
http://www.schembrionics.com
The Ultimate Solutions Center
The Ultimate Solutions Center
- alemao_brazil
- Newbie


- Joined: Feb 20, 2012
- Posts: 8
- Status: Offline
- ScottG
- Proficient


- Joined: Jul 06, 2010
- Posts: 266
- Status: Offline
I did do a test with your suggestion on using preg_match and using words like Sydney where y is both a vowel and a consonant It doesn't return anything. Sorry I didn't respond to your post earlier I've been a bit busy building a Christmas tree and before I went to bed or when i woke up and couldn't sleep I was working on my solution. It may have worked if tweaked a bit I never really got around to tweaking it though. Below is the code i used to test your suggestion
PHP Code: [ Select ]
start
<?php
function check_y($word) {
// Make an array to return info
$return_array = array();
# Credits: Sergio Abreu
# Matches y followed by vowel in any place...
if( preg_match( "/y[aeiou]/i", $word)){
$return_array[$word] = 'consonant';
} elseif( preg_match( "/[b-z]y/i", $word) && ! preg_match( "/[aeiou]y/i", $word)){
$return_array[$word] = 'vowel';
}
# To restrict y being the first letter, use ^ :
if( preg_match( "/^y[aeiou]/i", $word)){
$return_array[$word] = 'consonant';
} elseif( preg_match( "/[b-z]y/i", $word) && ! preg_match( "/[aeiou]y/i", $word)){
$return_array[$word] = 'vowel';
}
// Return the return array
return $return_array;
}
echo '<pre>';
var_dump(check_text('Sydney Billy Sylvia Missy Kyle Blythe Sylvester Katy Kay Yeltsin May Kuykendahl yes yam yell yellow yogurt yale gym my cycle baby hairy sky Lynn Yvonne Mary Betty Elly Bryan Maloney Murray Wyatt'));
//check_text('Sylvia');
echo '</pre>';
function check_text($text) {
// Make sure we have text
if(empty($text)) {
// Kick back
return false;
}
// Break text into words
$text_array = explode(' ', $text);
// Make an array to return info
$return_array = array();
// Loop Text
for($i=0; $i<count($text_array); $i++) {
// Add to the return array
$return_array[] = check_y($text_array[$i]);
}
// Return the array
return $return_array;
}
?>
done
<?php
function check_y($word) {
// Make an array to return info
$return_array = array();
# Credits: Sergio Abreu
# Matches y followed by vowel in any place...
if( preg_match( "/y[aeiou]/i", $word)){
$return_array[$word] = 'consonant';
} elseif( preg_match( "/[b-z]y/i", $word) && ! preg_match( "/[aeiou]y/i", $word)){
$return_array[$word] = 'vowel';
}
# To restrict y being the first letter, use ^ :
if( preg_match( "/^y[aeiou]/i", $word)){
$return_array[$word] = 'consonant';
} elseif( preg_match( "/[b-z]y/i", $word) && ! preg_match( "/[aeiou]y/i", $word)){
$return_array[$word] = 'vowel';
}
// Return the return array
return $return_array;
}
echo '<pre>';
var_dump(check_text('Sydney Billy Sylvia Missy Kyle Blythe Sylvester Katy Kay Yeltsin May Kuykendahl yes yam yell yellow yogurt yale gym my cycle baby hairy sky Lynn Yvonne Mary Betty Elly Bryan Maloney Murray Wyatt'));
//check_text('Sylvia');
echo '</pre>';
function check_text($text) {
// Make sure we have text
if(empty($text)) {
// Kick back
return false;
}
// Break text into words
$text_array = explode(' ', $text);
// Make an array to return info
$return_array = array();
// Loop Text
for($i=0; $i<count($text_array); $i++) {
// Add to the return array
$return_array[] = check_y($text_array[$i]);
}
// Return the array
return $return_array;
}
?>
done
- start
- <?php
- function check_y($word) {
- // Make an array to return info
- $return_array = array();
- # Credits: Sergio Abreu
- # Matches y followed by vowel in any place...
- if( preg_match( "/y[aeiou]/i", $word)){
- $return_array[$word] = 'consonant';
- } elseif( preg_match( "/[b-z]y/i", $word) && ! preg_match( "/[aeiou]y/i", $word)){
- $return_array[$word] = 'vowel';
- }
- # To restrict y being the first letter, use ^ :
- if( preg_match( "/^y[aeiou]/i", $word)){
- $return_array[$word] = 'consonant';
- } elseif( preg_match( "/[b-z]y/i", $word) && ! preg_match( "/[aeiou]y/i", $word)){
- $return_array[$word] = 'vowel';
- }
- // Return the return array
- return $return_array;
- }
- echo '<pre>';
- var_dump(check_text('Sydney Billy Sylvia Missy Kyle Blythe Sylvester Katy Kay Yeltsin May Kuykendahl yes yam yell yellow yogurt yale gym my cycle baby hairy sky Lynn Yvonne Mary Betty Elly Bryan Maloney Murray Wyatt'));
- //check_text('Sylvia');
- echo '</pre>';
- function check_text($text) {
- // Make sure we have text
- if(empty($text)) {
- // Kick back
- return false;
- }
- // Break text into words
- $text_array = explode(' ', $text);
- // Make an array to return info
- $return_array = array();
- // Loop Text
- for($i=0; $i<count($text_array); $i++) {
- // Add to the return array
- $return_array[] = check_y($text_array[$i]);
- }
- // Return the array
- return $return_array;
- }
- ?>
- done
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
December 25th, 2012, 2:25 pm
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 33 posts
- Users browsing this forum: No registered users and 124 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
