)我开始使用PEAR Number_Word类,它工作得很好!它通过这种方式将数字转换为字符串:
<?php
include_once 'Numbers/Words.php';
$number = 100254;
$nw = new Numbers_Words();
$numw = $nw->toWords($number);
print $numw;
?>但现在我需要同时将相同的数字转换为不同的语言。举个例子:我有100个数字,我需要同时把它转换成英语和法语。我试图在参数中传递两种语言的数组,但这不起作用:
/**
* Default Locale name
* @var string
* @access public
*/
public $locale = 'en_US'; //__her I was try to pass an array, but no result__
/**
* Default decimal mark
* @var string
* @access public
*/
public $decimalPoint = '.';
// }}}
// {{{ toWords()
/**
* Converts a number to its word representation
*
* @param integer $num An integer between -infinity and infinity inclusive :)
* that should be converted to a words representation
* @param string $locale Language name abbreviation. Optional. Defaults to
* current loaded driver or en_US if any.
* @param array $options Specific driver options
*
* @access public
* @author Piotr Klaban <makler@man.torun.pl>
* @since PHP 4.2.3
* @return string The corresponding word representation
*/
function toWords($num, $locale = '', $options = array())
{
if (empty($locale) && isset($this) && $this instanceof Numbers_Words) {
$locale = $this->locale;
}
if (empty($locale)) {
$locale = 'en_US';
}
$classname = self::loadLocale($locale, '_toWords');
$obj = new $classname;
if (!is_int($num)) {
$num = $obj->normalizeNumber($num);
// cast (sanitize) to int without losing precision
$num = preg_replace('/(.*?)('.preg_quote($obj->decimalPoint).'.*?)?$/', '$1', $num);
}
if (empty($options)) {
return trim($obj->_toWords($num));
}
return trim($obj->_toWords($num, $options));
}如果你知道怎么做,请叫我停一下!提前谢谢你!
发布于 2015-02-20 22:16:50
Numbers_Words不支持同时支持多种语言。
您需要为每种语言创建一个新的Numbers_Words实例。
https://stackoverflow.com/questions/27176370
复制相似问题