Home >Backend Development >PHP Tutorial >PHP program to convert Chinese date_PHP tutorial

PHP program to convert Chinese date_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:04:29750browse

This program outputs the Chinese date as 2001-12-23, and solves the problem of "ten" very well, such as the processing of "ten" in "Eleven" and "Twenty-one"! It can be changed to a function with slight modifications.
$str="December 23, 2001";
echo $str."

";
$flag=0;
$cn=array("one","two","three","four","five","six","seven","eight","nine","ten","zero" ,"○");
$num=array("1","2","3","4","5","6","7","8","9", "","0","0");
$len=strlen($str);
for ($i=0;$i<$len;$i+=2)
{
$array_str[$i]=substr($str,$i,2);
$cout=0;
while($cout {
if ($array_str[$i]==$cn[$cout])
{
if ($flag==1)
echo "-";
if (($array_str[$i ]=="十") and ($flag==1))
{
$temp[$cout]="1";
echo $temp[$cout];
$flag =2;break;
}
$temp[$cout]=$num[$cout];
echo $temp[$cout];
$flag=2;
break;
}
else
} {
if (count($cn)==$cout+1)
$flag=1;
}
$cout++; }
}
?>

http://www.bkjia.com/PHPjc/315908.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315908.htmlTechArticleThis program outputs the Chinese date as 2001-12-23, and solves the "ten" problem very well. Such as the treatment of "ten" in "eleven" and "twenty-one"! It can be changed to a function with slight modification. ? $str=二...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn