如何在PHP中将unicode转换为阿拉伯字符? [英] How to convert unicode to arabic characters in php?
问题描述
让我们说这个字符串是
$ uni_str =06280628002006280628;
在阿拉伯语中,它是:بببب
那么,如何在不使用html的情况下将其转换为PHP:
for($ i = 0; $ i< strlen($ uni_str); $ i + = 4)
{
$ text_str。=&#x.substr($ uni_str,$ i,4)。;;
}
只是解决了在html页面查看结果的问题, / p>
但是我想但是结果在php变量中。
由于上述代码的结果就像
&#x0628;&#x0628;&#x0020;&#x0020;&#x0628;& #x0628;
我找到了解决方案, p
$ b $ pre $ 函数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;
变量$全部包含阿拉伯字符串
let us say that the string is
$uni_str="06280628002006280628";
In Arabic,it is: بب بب
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).";";
}
as this code just solves the problem of viewing the result in html page ,
but i want to but the result in php variable .
as the result of the code above was like
بب  بب
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;
}
variable $All contains the arabic string
这篇关于如何在PHP中将unicode转换为阿拉伯字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!