首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阿拉伯语字符到arabic字符

阿拉伯语字符到arabic字符
EN

Stack Overflow用户
提问于 2021-09-07 14:51:53
回答 1查看 39关注 0票数 2

我正在使用php中的以下代码来显示罗马ABCD字符中的阿拉伯字母,正如我的代码中定义的那样。

但是它不能正确显示。它还丢失了字符排序,并且不能根据我的字符串显示某些字符。

它显示为_space_aabtkhlmn,并且应该显示为khatm_space_alanbyaa

我想不出我哪里错了。

请帮帮忙,为什么显示错误?

代码语言:javascript
复制
<!DOCTYPE HTML>
<head>
    <?php header('Content-type: text/html; charset=utf-8'); ?>
</head>
<body>
 <?php
echo $mystr =   "خاتم الانبیاء";

echo "<hr>";
$empty  =   " ";
$a = "ء";
$a1 = "ا";
$a2 = "آ";
$b = "ب";
$c = "پ";
$d = "ة";
$e = "ت";
$ea = "ٹ";
$f = "ث";
$g = "ج";
$h = "چ";
$ha = "ح";
$i = "خ";
$j = "د";
$ja = "ڈ";
$k = "ذ";
$l = "ر";
$m = "ڑ";
$ma = "ز";
$mb = "ژ";
$n = "س";
$na = "ش";
$nb = "ص ";
$nc = "ض";
$o = "ط";
$p = "ظ";
$q = "ع";
$r = "غ";
$s = "ف";
$t = "ق";
$ta = "ک";
$tb = "گ";
$u = "ل";
$v = "م";
$w = "ن";
$wa = "ں";
$x = "ہ";
$xa = "ھ";
$y = "و";
$ya = "ے";
$yb = "ى";
$yc = "ي";

$me     =   preg_split('//u', $mystr);
$imp    =   implode(",", $me);
    
echo "<div style='direction: ltr;'>";
if(stripos($imp, $empty) == true){ echo "_space_"; }
if(stripos($imp, $a) == true){ echo "a"; }
if(stripos($imp, $a1) == true){ echo "a";}
if(stripos($imp, $a2) == true){ echo "aa";}
if(stripos($imp, $b) == true){ echo "b";}
if(stripos($imp, $c) == true){ echo "p";}
if(stripos($imp, $d) == true){ echo "h";}
if(stripos($imp, $e) == true){ echo "t";}
if(stripos($imp, $ea) == true){ echo "t";}
if(stripos($imp, $f) == true){ echo "s";}
if(stripos($imp, $g) == true){ echo "j";}
if(stripos($imp, $h) == true){ echo "ch";}
if(stripos($imp, $ha) == true){ echo "h";}
if(stripos($imp, $i) == true){ echo "kh";}
if(stripos($imp, $j) == true){ echo "d";}
if(stripos($imp, $ja) == true){ echo "d";}
if(stripos($imp, $k) == true){ echo "z";}
if(stripos($imp, $l) == true){ echo "r";}
if(stripos($imp, $m) == true){ echo "rr";}
if(stripos($imp, $ma) == true){ echo "z";}
if(stripos($imp, $mb) == true){ echo "x";}
if(stripos($imp, $n) == true){ echo "s";}
if(stripos($imp, $na) == true){ echo "sh";}
if(stripos($imp, $nb) == true){ echo "s";}
if(stripos($imp, $nc) == true){ echo "d";}
if(stripos($imp, $o) == true){ echo "t";}
if(stripos($imp, $p) == true){ echo "z";}
if(stripos($imp, $q) == true){ echo "u";}
if(stripos($imp, $r) == true){ echo "gh";}
if(stripos($imp, $s) == true){ echo "f";}
if(stripos($imp, $t) == true){ echo "q";}
if(stripos($imp, $ta) == true){ echo "k";}
if(stripos($imp, $tb) == true){ echo "g";}
if(stripos($imp, $u) == true){ echo "l";}
if(stripos($imp, $v) == true){ echo "m";}
if(stripos($imp, $w) == true){ echo "n";}
if(stripos($imp, $wa) == true){ echo "n";}
if(stripos($imp, $x) == true){ echo "h";}
if(stripos($imp, $xa) == true){ echo "h";}
if(stripos($imp, $y) == true){ echo "o";}
if(stripos($imp, $ya) == true){ echo "y";}
if(stripos($imp, $yb) == true){ echo "y";}
if(stripos($imp, $yc) == true){ echo "y";}
echo "</div>";
echo "<hr>";
?>
</body>
</html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-07 15:52:12

您的逻辑将字符串拆分为逗号分隔的字符。然后检查空格是否在字符串中的任何位置,如果是,则打印_space_,然后检查ء是否在字符串中的任何位置,如果是,则打印"a",然后检查ا是否在字符串中的任何位置,如果是,则打印“aa”。这将按照您测试的顺序打印结果,而不是字符串的顺序。

我相信你的意思是这样的:

代码语言:javascript
复制
$mystr = str_replace($empty, "_space_", $mystr);
$mystr = str_replace($a, "a", $mystr);
$mystr = str_replace($a1, "a", $mystr);
$mystr = str_replace($a2, "aa", $mystr);
$mystr = str_replace($b, "b", $mystr);
$mystr = str_replace($c, "p", $mystr);
$mystr = str_replace($d, "h", $mystr);
$mystr = str_replace($e, "t", $mystr);
$mystr = str_replace($ea, "t", $mystr);
$mystr = str_replace($f, "s", $mystr);
...

这是可行的,除了你的逻辑中的一个小问题。您的字符串包含波斯语ی(U+06CC),但您不检查它。你只检查乌尔都语(U+06D2;ے?我不知道这个),阿拉伯语(U+0649 Alef Maksura)和阿拉伯语(U+064Aى)。所以你需要另外一行:

代码语言:javascript
复制
$yd = "ی"; // ARABIC LETTER FARSI YEH (U+06CC)
...
$mystr = str_replace($yd, "y", $mystr);

有没有可能你想把Alef Maksura换成"a“而不是"y"?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69090382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档