我正在尝试用希腊语写成拉丁语和特殊字符的文字。
他是我的字母数组:
$this->greeklish = array(
'α' => array('a'),
'ά' => array('a'),
'Ά' => array('A'),
'Α' => array('A'),
'β' => array('b', 'v'),
'Β' => array('B', 'V'),
'γ' => array('g'),
'Γ' => array('G'),
'δ' => array('d'),
'Δ' => array('D'),
'ε' => array('e'),
'έ' => array('e'),
'Ε' => array('E'),
'Έ' => array('E'),
'ζ' => array('z'),
'Ζ' => array('Z'),
'η' => array('h', 'i'),
'ή' => array('h', 'i'),
'Η' => array('H', 'I'),
'θ' => array('th', '8', '3'),
'Θ' => array('Th', 'TH', '8', '3'),
'ι' => array('i'),
'ί' => array('i'),
'ϊ' => array('i'),
'ΐ' => array('i'),
'Ι' => array('I'),
'Ί' => array('I'),
'κ' => array('k'),
'Κ' => array('K'),
'λ' => array('l'),
'Λ' => array('L'),
'μ' => array('m'),
'Μ' => array('M'),
'ν' => array('n'),
'Ν' => array('N'),
'ξ' => array('x', 'ks'),
'Ξ' => array('X', 'Ks', 'KS'),
'ο' => array('o'),
'ό' => array('o'),
'Ο' => array('O'),
'Ό' => array('O'),
'π' => array('p'),
'Π' => array('P'),
'ρ' => array('r'),
'Ρ' => array('R'),
'σ' => array('s'),
'ς' => array('s'),
'Σ' => array('S'),
'τ' => array('t'),
'Τ' => array('T'),
'υ' => array('u', 'y'),
'ύ' => array('U', 'Y'),
'Υ' => array('u', 'y'),
'Ύ' => array('u', 'Y'),
'φ' => array('f'),
'Φ' => array('F'),
'χ' => array('x'),
'Χ' => array('X'),
'ψ' => array('ps'),
'Ψ' => array('Ps', 'PS'),
'ω' => array('w', 'o'),
'ώ' => array('w', 'o'),
'Ω' => array('W', 'O'),
'Ώ' => array('W', 'O')
);
这是替换希腊字母的函数,这些字母对应于具有1个元素的数组。
public function translateSingle($word){
$wordArr = mb_str_split($word); // function to split word into letters
foreach ($wordArr as $grKey => &$grLetter) {
$alts = $this->getLetterAlternatives($grLetter); // function that get the alternatives from the above array
if ( count($alts) === 1 ) {
$grLetter = $alts[0];
$this->translateSingle(@implode($wordArr));
}
}
return implode($wordArr);
}
正如您所看到的那样,有些字母可以被许多拉丁字符替换/写入。
执行translateSingle()
后,我想基于上面的数组生成所有可能的单词组合。
示例:
执行translateSingle()
后希腊词“πρώτη”将成为“prώtη”
但所有可能的组合是:
'prwti'
'prwth'
'proth'
'proti'
PS:我正在传递一个希腊字数组作为此脚本的源。