php– 如何将印地语(梵文脚本)转换为英文字母

php– 如何将印地语(梵文脚本)转换为英文字母,第1张

概述我面临的问题是将用梵文脚本编写的印地文文本转换为英文/拉丁文字母.我有一个名字列表,其中一些名称如name field =सचिन但我想将其转换为Sachin以显示在前端.是否有任何代码使用谷歌翻译翻译脚本.仅供参考:我只需翻译整个句子或页面不需要翻译的名称.最佳答案我不知道印地语,但以下$charsArray包含了大部分来自着名语言(包括印地语)的字母.

我面临的问题是将用梵文脚本编写的印地文文本转换为英文/拉丁文字母.我有一个名字列表,其中一些名称如name fIEld =सचिन但我想将其转换为Sachin以显示在前端.
是否有任何代码使用谷歌翻译翻译脚本.

仅供参考:我只需翻译整个句子或页面不需要翻译的名称.

最佳答案我不知道印地语,但以下$charsArray包含了大部分来自着名语言(包括印地语)的字母. (它来自Laravel Core).

function ascii($value,$charsArray){    foreach ($charsArray as $key => $val) {        $value = str_replace($val,$key,$value);    }    return preg_replace('/[^x20-x7E]/u','',$value);}$charsArray = [        '0'    => ['°','₀','۰'],'1'    => ['¹','₁','۱'],'2'    => ['²','₂','۲'],'3'    => ['³','₃','۳'],'4'    => ['⁴','₄','۴','٤'],'5'    => ['⁵','₅','۵','٥'],'6'    => ['⁶','₆','۶','٦'],'7'    => ['⁷','₇','۷'],'8'    => ['⁸','₈','۸'],'9'    => ['⁹','₉','۹'],'a'    => ['à','á','ả','ã','ạ','ă','ắ','ằ','ẳ','ẵ','ặ','â','ấ','ầ','ẩ','ẫ','ậ','ā','ą','å','α','ά','ἀ','ἁ','ἂ','ἃ','ἄ','ἅ','ἆ','ἇ','ᾀ','ᾁ','ᾂ','ᾃ','ᾄ','ᾅ','ᾆ','ᾇ','ὰ','ᾰ','ᾱ','ᾲ','ᾳ','ᾴ','ᾶ','ᾷ','а','أ','အ','ာ','ါ','ǻ','ǎ','ª','ა','अ','ا'],'b'    => ['б','β','Ъ','Ь','ب','ဗ','ბ'],'c'    => ['ç','ć','č','ĉ','ċ'],'d'    => ['ď','ð','đ','ƌ','ȡ','ɖ','ɗ','ᵭ','ᶁ','ᶑ','д','δ','د','ض','ဍ','ဒ','დ'],'e'    => ['é','è','ẻ','ẽ','ẹ','ê','ế','ề','ể','ễ','ệ','ë','ē','ę','ě','ĕ','ė','ε','έ','ἐ','ἑ','ἒ','ἓ','ἔ','ἕ','ὲ','е','ё','э','є','ə','ဧ','ေ','ဲ','ე','ए','إ','ئ'],'f'    => ['ф','φ','ف','ƒ','ფ'],'g'    => ['ĝ','ğ','ġ','ģ','г','ґ','γ','ဂ','გ','گ'],'h'    => ['ĥ','ħ','η','ή','ح','ه','ဟ','ှ','ჰ'],'i'    => ['í','ì','ỉ','ĩ','ị','î','ï','ī','ĭ','į','ı','ι','ί','ϊ','ΐ','ἰ','ἱ','ἲ','ἳ','ἴ','ἵ','ἶ','ἷ','ὶ','ῐ','ῑ','ῒ','ῖ','ῗ','і','ї','и','ဣ','ိ','ီ','ည်','ǐ','ი','इ'],'j'    => ['ĵ','ј','Ј','ჯ','ج'],'k'    => ['ķ','ĸ','к','κ','Ķ','ق','ك','က','კ','ქ','ک'],'l'    => ['ł','ľ','ĺ','ļ','ŀ','л','λ','ل','လ','ლ'],'m'    => ['м','μ','م','မ','მ'],'n'    => ['ñ','ń','ň','ņ','ʼn','ŋ','ν','н','ن','န','ნ'],'o'    => ['ó','ò','ỏ','õ','ọ','ô','ố','ồ','ổ','ỗ','ộ','ơ','ớ','ờ','ở','ỡ','ợ','ø','ō','ő','ŏ','ο','ὀ','ὁ','ὂ','ὃ','ὄ','ὅ','ὸ','ό','о','و','θ','ို','ǒ','ǿ','º','ო','ओ'],'p'    => ['п','π','ပ','პ','پ'],'q'    => ['ყ'],'r'    => ['ŕ','ř','ŗ','р','ρ','ر','რ'],'s'    => ['ś','š','ş','с','σ','ș','ς','س','ص','စ','ſ','ს'],'t'    => ['ť','ţ','т','τ','ț','ت','ط','ဋ','တ','ŧ','თ','ტ'],'u'    => ['ú','ù','ủ','ũ','ụ','ư','ứ','ừ','ử','ữ','ự','û','ū','ů','ű','ŭ','ų','µ','у','ဉ','ု','ူ','ǔ','ǖ','ǘ','ǚ','ǜ','უ','उ'],'v'    => ['в','ვ','ϐ'],'w'    => ['ŵ','ω','ώ','ဝ','ွ'],'x'    => ['χ','ξ'],'y'    => ['ý','ỳ','ỷ','ỹ','ỵ','ÿ','ŷ','й','ы','υ','ϋ','ύ','ΰ','ي','ယ'],'z'    => ['ź','ž','ż','з','ζ','ز','ဇ','ზ'],'aa'   => ['ع','आ','آ'],'ae'   => ['ä','æ','ǽ'],'ai'   => ['ऐ'],'at'   => ['@'],'ch'   => ['ч','ჩ','ჭ','چ'],'dj'   => ['ђ','đ'],'dz'   => ['џ','ძ'],'ei'   => ['ऍ'],'gh'   => ['غ','ღ'],'ii'   => ['ई'],'ij'   => ['ij'],'kh'   => ['х','خ','ხ'],'lj'   => ['љ'],'nj'   => ['њ'],'oe'   => ['ö','œ','ؤ'],'oi'   => ['ऑ'],'oii'  => ['ऒ'],'ps'   => ['ψ'],'sh'   => ['ш','შ','ش'],'shch' => ['щ'],'ss'   => ['ß'],'sx'   => ['ŝ'],'th'   => ['þ','ϑ','ث','ذ','ظ'],'ts'   => ['ц','ც','წ'],'ue'   => ['ü'],'uu'   => ['ऊ'],'ya'   => ['я'],'yu'   => ['ю'],'zh'   => ['ж','ჟ','ژ'],'(c)'  => ['©'],'A'    => ['Á','À','Ả','Ã','Ạ','Ă','Ắ','Ằ','Ẳ','Ẵ','Ặ','Â','Ấ','Ầ','Ẩ','Ẫ','Ậ','Å','Ā','Ą','Α','Ά','Ἀ','Ἁ','Ἂ','Ἃ','Ἄ','Ἅ','Ἆ','Ἇ','ᾈ','ᾉ','ᾊ','ᾋ','ᾌ','ᾍ','ᾎ','ᾏ','Ᾰ','Ᾱ','Ὰ','ᾼ','А','Ǻ','Ǎ'],'B'    => ['Б','Β','ब'],'C'    => ['Ç','Ć','Č','Ĉ','Ċ'],'D'    => ['Ď','Ð','Đ','Ɖ','Ɗ','Ƌ','ᴅ','ᴆ','Д','Δ'],'E'    => ['É','È','Ẻ','Ẽ','Ẹ','Ê','Ế','Ề','Ể','Ễ','Ệ','Ë','Ē','Ę','Ě','Ĕ','Ė','Ε','Έ','Ἐ','Ἑ','Ἒ','Ἓ','Ἔ','Ἕ','Ὲ','Е','Ё','Э','Є','Ə'],'F'    => ['Ф','Φ'],'G'    => ['Ğ','Ġ','Ģ','Г','Ґ','Γ'],'H'    => ['Η','Ή','Ħ'],'I'    => ['Í','Ì','Ỉ','Ĩ','Ị','Î','Ï','Ī','Ĭ','Į','İ','Ι','Ί','Ϊ','Ἰ','Ἱ','Ἳ','Ἴ','Ἵ','Ἶ','Ἷ','Ῐ','Ῑ','Ὶ','И','І','Ї','Ǐ','ϒ'],'K'    => ['К','Κ'],'L'    => ['Ĺ','Ł','Л','Λ','Ļ','Ľ','Ŀ','ल'],'M'    => ['М','Μ'],'N'    => ['Ń','Ñ','Ň','Ņ','Ŋ','Н','Ν'],'O'    => ['Ó','Ò','Ỏ','Õ','Ọ','Ô','Ố','Ồ','Ổ','Ỗ','Ộ','Ơ','Ớ','Ờ','Ở','Ỡ','Ợ','Ø','Ō','Ő','Ŏ','Ο','Ό','Ὀ','Ὁ','Ὂ','Ὃ','Ὄ','Ὅ','Ὸ','О','Θ','Ө','Ǒ','Ǿ'],'P'    => ['П','Π'],'R'    => ['Ř','Ŕ','Р','Ρ','Ŗ'],'S'    => ['Ş','Ŝ','Ș','Š','Ś','С','Σ'],'T'    => ['Ť','Ţ','Ŧ','Ț','Т','Τ'],'U'    => ['Ú','Ù','Ủ','Ũ','Ụ','Ư','Ứ','Ừ','Ử','Ữ','Ự','Û','Ū','Ů','Ű','Ŭ','Ų','У','Ǔ','Ǖ','Ǘ','Ǚ','Ǜ'],'V'    => ['В'],'W'    => ['Ω','Ώ','Ŵ'],'X'    => ['Χ','Ξ'],'Y'    => ['Ý','Ỳ','Ỷ','Ỹ','Ỵ','Ÿ','Ῠ','Ῡ','Ὺ','Ύ','Ы','Й','Υ','Ϋ','Ŷ'],'Z'    => ['Ź','Ž','Ż','З','Ζ'],'AE'   => ['Ä','Æ','Ǽ'],'CH'   => ['Ч'],'DJ'   => ['Ђ'],'DZ'   => ['Џ'],'GX'   => ['Ĝ'],'HX'   => ['Ĥ'],'IJ'   => ['IJ'],'JX'   => ['Ĵ'],'KH'   => ['Х'],'LJ'   => ['Љ'],'NJ'   => ['Њ'],'OE'   => ['Ö','Œ'],'PS'   => ['Ψ'],'SH'   => ['Ш'],'SHCH' => ['Щ'],'SS'   => ['ẞ'],'TH'   => ['Þ'],'TS'   => ['Ц'],'UE'   => ['Ü'],'YA'   => ['Я'],'YU'   => ['Ю'],'ZH'   => ['Ж'],' '    => ["xC2xA0","xE2x80x80","xE2x80x81","xE2x80x82","xE2x80x83","xE2x80x84","xE2x80x85","xE2x80x86","xE2x80x87","xE2x80x88","xE2x80x89","xE2x80x8A","xE2x80xAF","xE2x81x9F","xE3x80x80"],];

所以你需要做的是在函数中插入印地语名称,它将返回相当于名称字母的英语(不翻译).

$englishname = ascii($indianname,$charsArray);

如果$charsArray不包含您需要的所有字母,或者您只需要自定义它,您可以轻松地在$charsArray的键中添加英文字母,并在相应的数组中添加它的印地语翻译(值).你完成了!
谢谢Taylor Otwell&创意Laravel团队. 总结

以上是内存溢出为你收集整理的php – 如何将印地语(梵文脚本)转换为英文字母全部内容,希望文章能够帮你解决php – 如何将印地语(梵文脚本)转换为英文字母所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1119306.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存