2014-09-04 53 views
0

转换拼音我想数字转换成字母数字 ,但问题是十进制数字将不会转换数字转换为字母的法文 - PHP

我认为,在代码

这部分问题
if (null !== $fraction && is_numeric($fraction)) { 
     $string .= $decimal; 
     $words = array(); 
     foreach (str_split((string) $fraction) as $number) { 
      $words[] = $dictionary[$number]; 
     } 
     $string .= implode(' ', $words); 
    } 
return $string; 
    } 

    $montant_alph = convert_number_to_words($a)." MAD"; 
+0

请解释它没有做什么,你期望它会做什么和你尝试过什么。这将有助于读者回答你的问题 – Roalt 2014-09-04 11:04:24

+0

请提供样本输入和输出等 – Jonathon 2014-09-04 11:05:24

+0

请大家看看这是文件文本:[http://textuploader.com/o5n1] – 2014-09-04 13:51:04

回答

0

您不需要str_split将小数部分转换为数组。

$dictionary = array(
    1 => 'zero', 
    1 => 'un', 
    2 => 'deux', 
    3 => 'trois', 
    4 => 'quatre', 
    5 => 'cinq', 
    6 => 'six', 
    7 => 'sept', 
    8 => 'huit', 
    9 => 'neuf', 
); 
// example 422.6543 
$fraction = (integer) 6543; 
$decimal = 'quatre deux deux/'; 

if (null !== $fraction && is_numeric($fraction)) { 
    $string .= $decimal; 
    $words = array(); 
    $fraction = (string) $fraction; 
    for ($i = 0; $i < strlen($fraction); ++$i) { 
     $words[] = $dictionary[$fraction{$i}]; 
    } 
    $string .= implode(' ', $words); 
} 
+0

已经完成,但它不起作用 看这是文件的文本:[http://textuploader.com/o5n1] – 2014-09-04 13:49:58