我很想知道是否有一个脚本可以将英文字符放在普通的ascii字符中而没有任何重音。我想要这个的原因是因为我有一个基于给定的提交公司名称动态创建数据库的Web应用程序。
到目前为止,我已经能够构建这个代码,它似乎运行良好但仅适用于英语,斯拉夫语和希腊语字符。理想情况下,我希望将它用于所有语言,但是通过所有字符(包括重音符号)来实现这一点似乎很乏味。
class englishfy
{
public $array = array();
public function __construct()
{
$this->add_str("<empty>","ьъ");
$this->add_str("a","аαάáąäăâăàā"); $this->add_str("ae","æ"); $this->add_str("b","бβb");$this->add_str("c","ćčç");
$this->add_str("ch","чхχ"); $this->add_str("d","дδđ"); $this->add_str("e","еэεєęěéêëèēέ"); $this->add_str("f","фφ");
$this->add_str("g","гγґğ"); $this->add_str("i","иыіηήιϊίíîïìī"); $this->add_str("k","кκķ"); $this->add_str("l","лλ");
$this->add_str("m","мμ"); $this->add_str("n","нνňñ"); $this->add_str("ny","ń"); $this->add_str("o","оοωώόóöôòõø");
$this->add_str("p","пπ"); $this->add_str("ps","ψ"); $this->add_str("r","рρř"); $this->add_str("s","сσςšşșś");
$this->add_str("sh","шщ"); $this->add_str("ss","ß"); $this->add_str("sz","ж"); $this->add_str("t","тτț");
$this->add_str("th","θ"); $this->add_str("ts","ц"); $this->add_str("u","уυύúůüùûū"); $this->add_str("v","в");
$this->add_str("w","ł"); $this->add_str("x","ξ"); $this->add_str("y","йýÿý"); $this->add_str("ya","я");
$this->add_str("ye","ї");$this->add_str("yo","ё");$this->add_str("yu","ю"); $this->add_str("z","зζżźž");
}
private function add_str($string,$chars)
{
$this->array[$string]=array();
$this->array[mb_strtoupper($string)]=array();
$chars=mb_strtolower($chars);
$l=mb_strlen($chars);
for($n=0;$n<$l;$n++)
{
$letter = mb_substr($chars,$n,1);
if(!in_array($letter,$this->array[$string]) and $letter !== $string)
{
array_push($this->array[$string],$letter);
array_push($this->array[mb_strtoupper($string)],mb_strtoupper($letter));
}
}
}
public function return_english($string)
{
foreach($this->array as $key => $value){if (is_array($value)){$string = str_replace($value,$key,$string);}}
return str_replace("<empty>","",$string);
}
}
//#########################################
$obj = new englishfy();
echo $obj->return_english("Hello, Привет, Köszönni, Γειά σου, cześć ");//returns Hello, Privet, Koszonni, Geia sou, czesc