symfony 2如何使数字出现在西方阿拉伯语中 [英] symfony 2 how to make numbers appear in western arabic

查看:61
本文介绍了symfony 2如何使数字出现在西方阿拉伯语中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用symfony2创建一个阿拉伯语网站! 当我将语言环境设置为阿拉伯语的"ar"时,即使数字也转换为阿拉伯语!

i am making an arabic website with symfony2 ! when i set the locale as "ar" for arabic, even numbers are converted in arabic !

西方阿拉伯语0 1 2 3 4 5 6 7 8 9 成为: 东部阿拉伯语p ٩ ٩

Western Arabic 0 1 2 3 4 5 6 7 8 9 became: Eastern Arabic ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩

有没有一种解决方法可以使数字以西数形式出现?

is there a solution to make the numbers appears in the wester form ?

谢谢!

推荐答案

<?php

/**
* Converts numbers in string from western to eastern Arabic numerals.
*
* @param string $str Arbitrary text
* @return string Text with western Arabic numerals converted into eastern Arabic numerals.
*/
function arabic_w2e($str) {
$arabic_eastern = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
$arabic_western = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
return str_replace($arabic_western, $arabic_eastern, $str);
}

/**
* Converts numbers from eastern to western Arabic numerals.
*
* @param string $str Arbitrary text
* @return string Text with eastern Arabic numerals converted into western Arabic numerals.
*/
function arabic_e2w($str) {
$arabic_eastern = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
$arabic_western = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
return str_replace($arabic_eastern, $arabic_western, $str);
}

这篇关于symfony 2如何使数字出现在西方阿拉伯语中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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