How to find next letter in string using mbstring function?
Posted: Mon Jan 21, 2008 4:03 pm
Hello, can anyone suggest a method of locating the next letter in a string using one of the mb string functions?
I have a form where the user enters Greek script (unicode) and the php script then tries to convert this into the latin alpabet so users can tell how to pronounce the word.
A particular rule that I have to implement is the following: If a string contains the Greek characters "??" then I need to find what the next character is so I can convert it correctly. If it is an "?" then the "??" needs to be converted to "ef", if not then it converts to an "ev".
I've tried doing the code I've posted in below, but whilst the script works when I'm debugging in my editor, it doesn't when running it from my browser. Hence, I'm looking for an alternative that doesn't use mb_substr() as that is the routine that is not working consistently for me.
Thanks,
Tim.
I have a form where the user enters Greek script (unicode) and the php script then tries to convert this into the latin alpabet so users can tell how to pronounce the word.
A particular rule that I have to implement is the following: If a string contains the Greek characters "??" then I need to find what the next character is so I can convert it correctly. If it is an "?" then the "??" needs to be converted to "ef", if not then it converts to an "ev".
I've tried doing the code I've posted in below, but whilst the script works when I'm debugging in my editor, it doesn't when running it from my browser. Hence, I'm looking for an alternative that doesn't use mb_substr() as that is the routine that is not working consistently for me.
Code: Select all
$input = "?????????";
$pos = mb_strpos($input, "??");
if ($pos >= 0)
{
$NextLetter = mb_substr($input, $pos + 2, 1);
}
if ($NextLetter == "?")
{
$input = mb_ereg_replace("??", "ef", $input);
}
else
{
$input = mb_ereg_replace("??", "ev", $input);
}
Tim.