donglan7594 2014-11-07 12:51
浏览 69

带有阿拉伯字符的str_replace

i try to replace some arabic caractere with another symbole some arbic caractere is replaced but one of this caractere it not replaced first i try to split the word second try to replace the caractere the caractere is َ ً ٍ ِ ْ ُ all this are replaced but the problem is with this caractere ّ strong text this is the code

   $spelling="";

function str_split_unicode($str, $l = 0) {

if ($l > 0) {

$ret = array();

$len = mb_strlen($str, "UTF-8");

for ($i = 0; $i < $len; $i += $l) {

$ret[] = mb_substr($str, $i, $l, "UTF-8");

}
return $ret;
}
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}

if(isset($_POST['txt_word'])){

 $spelling = implode("  ", str_split_unicode($_POST['txt_word']));

}


 $search  = array('ّّ ','ً ','ٍ ','ٌ ','ُ ','َ ','ِ ','ْ ');

$replace = array('0/','/0','/0','/0','/','/','/','0');

$subject= str_replace($search, $replace,  $spelling);

$alphabet=array('أ','ا','ب','ت','ث','ج','ح','خ','د','ذ','ر','ز','س','ش','س','ص','ط','ظ','ع','غ','ف','ق','ل','م','ن','ه','و','ي','لا','ة','إ','ئ','ؤ','ك','ى','ء');

$rep=array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');

$res=str_replace($alphabet,$rep,$subject);
  • 写回答

2条回答 默认 最新

  • duancenxiao0482 2014-11-07 13:09
    关注

    str_replace() should be able to handle Unicode characters If it does not, you are probably not passing it Unicode.

    Make sure that you are handling Unicode strings all the way through from the displayed website to the PHP script. See this article for further information: „Unicode-friendly PHP and MySQL“.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题