How to find next letter in string using mbstring function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timski72
Forum Newbie
Posts: 15
Joined: Sun Jan 13, 2008 6:19 am

How to find next letter in string using mbstring function?

Post by timski72 »

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.

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);
}
 
Thanks,
Tim.
Post Reply