PHP数字を大文字に変換

1076 ワード

function str_num($num){
$str = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
$unit = array('',' ',' ',' ');
$num_arr = str_split(strval($num));
$new_arr = array_reverse($num_arr);
$arr = array();
$wan = array();
$yi  = array();
foreach($new_arr as $key=>$val){
    $index = $key%4;
    $char = $str[$val];
    $char .= $unit[$index];
    $div = floor($key/4);
    if($val == 0){
      if($key>0 && $new_arr[$key-1] !=0 && $index!=0){
         $char = ' ';
      }else{
          continue;
      }
    }
    if($div == 1){
        array_unshift($wan,$char);
    }elseif($div == 2){
        array_unshift($yi,$char);
    }else{
        array_unshift($arr,$char);
    }
  }
  $yi = ($yi)?implode('',$yi).' ':'';
  $wan = ($wan)?implode('',$wan).' ':'';
  $base = implode('',$arr);
  return $yi.$wan.$base;

}
echo str_num($argv[1]);