Chinese | convert <?php
The Sea and Canada
2000-7-19
Class Chinesenumber
{
var $basical =array (0=> "0", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine");
var $basical =array (0=> "0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "Nine");
var $advanced =array (1=> "Ten", "Hundred", "thousand");
var $advanced =array (1=> "Pick Up", "Bai", "Qian");
var $top =array (1=> "million", "billion");
var $level; At 4-bit level
First realize the conversion of the number in case
function Parsenumber ($number)
{
if ($number >999999999999)//can only be processed to billions.
Return "The number is too large to handle. I'm sorry! ";
if ($number ==0)
return "0";
For ($this->level=0; $number >0.0001; $this->level++, $number =floor ($number/10000))
{
For Chinese, it should be a group of 4-bit.
The four variables correspond to one, ten, hundred, and thousands respectively.
$n 1=substr ($number, -1,1);
if ($number >9)
$n 2=substr ($number, -2,1);
Else
$n 2=0;
if ($number >99)
$n 3=substr ($number, -3,1);
Else
$n 3=0;
if ($number >999)
$n 4=substr ($number, -4,1);
Else
$n 4=0;
if ($n 4)
$parsed [$this->level].= $this->basical[$n 4]. $this->advanced[3];
Else
if (($number/10000) >=1)//thousand is 0, the value is greater than 9999
$parsed [$this->level].= "0";
if ($n 3)
$parsed [$this->level].= $this->basical[$n 3]. $this->advanced[2];
Else
if (!ereg ("0 $", $parsed [$this->level]) && ($number/1000) >=1)//does not appear two consecutive "0"
$parsed [$this->level].= "0";
if ($n 2)
$parsed [$this->level].= $this->basical[$n 2]. $this->advanced[1];
Else
if (!ereg ("0 $", $parsed [$this->level]) && ($number/100) >=1)//does not appear two consecutive "0"
$parsed [$this->level].= "0";
if ($n 1)
$parsed [$this->level].= $this->basical[$n 1];
}
For ($this->level-=1; $this->level>=0; $this->level--)
{
$result. = $parsed [$this->level]. $this->top[$this->level];
}
if (Ereg ("0 $", $result))
$result =substr ($result, 0,strlen ($result)-2);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.