cfructose
03-14-2010, 12:20 AM
I'm trying to find the position of the first vowel in a string, where the vowels are written in Kirshenbaum phonetic script.
Is there a php inbuilt function similar to strpos, but where the position in the string we're searching is returned based on any value from an array, rather than just a '$needle' string?
I ask because the following code, while succinct enough, seems a little on the convoluted side for something so simple. Could it be rewritten without the for loop?
Any suggestions for improvement?
//Array of symbols used to represent vowels in a system not unliek X-SAMPA
$Kirshenbaum['vowels'] = array(
'A', '&', 'a', 'V', '@', 'e', '3', 'I', 'i', '0', 'O', 'o', 'u', 'U'
);
for ($i=0; $i<count($Kirshenbaum['vowels']); $i++) {
$pos = strpos($word, $Kirshenbaum['vowels'][$i]);
if ($pos !== FALSE) {
break;
}
}
Thanks
Is there a php inbuilt function similar to strpos, but where the position in the string we're searching is returned based on any value from an array, rather than just a '$needle' string?
I ask because the following code, while succinct enough, seems a little on the convoluted side for something so simple. Could it be rewritten without the for loop?
Any suggestions for improvement?
//Array of symbols used to represent vowels in a system not unliek X-SAMPA
$Kirshenbaum['vowels'] = array(
'A', '&', 'a', 'V', '@', 'e', '3', 'I', 'i', '0', 'O', 'o', 'u', 'U'
);
for ($i=0; $i<count($Kirshenbaum['vowels']); $i++) {
$pos = strpos($word, $Kirshenbaum['vowels'][$i]);
if ($pos !== FALSE) {
break;
}
}
Thanks