如何在 php 中将 unicode 转换为阿拉伯字符? [英] How to convert unicode to arabic characters in php?

查看:40
本文介绍了如何在 php 中将 unicode 转换为阿拉伯字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说字符串是

$uni_str="06280628002006280628";

在阿拉伯语中,它是:بب بب

In Arabic,it is: بب بب

那么,如何在不使用 html 的情况下在 php 中转换它,例如:

so , how can i convert it in php without using html like:

    for($i=0; $i<strlen($uni_str); $i+=4)
    {
        $text_str .= "&#x".substr($uni_str,$i,4).";";
    }

因为这段代码只是解决了在html页面查看结果的问题,

as this code just solves the problem of viewing the result in html page ,

但我想但是结果在 php 变量中.

but i want to but the result in php variable .

因为上面代码的结果就像

as the result of the code above was like

&#x0628;&#x0628;&#x0020;&#x0020;&#x0628;&#x0628;

推荐答案

我找到了解决方案,希望能帮到你:

I found the solution , hope to help:

function uni2arabic($uni_str) 
{   
      for($i=0; $i<strlen($uni_str); $i+=4)
         {
                $new="&#x".substr($uni_str,$i,4).";"; 
                $txt = html_entity_decode("$new", ENT_COMPAT, "UTF-8");
                $All.=$txt;
         }

    return $All;
} 

变量 $All 包含阿拉伯字符串

variable $All contains the arabic string

这篇关于如何在 php 中将 unicode 转换为阿拉伯字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆