转换中文日期的PHP程序
发布时间:2006-10-14 2:45:51   收集提供:gaoqian
本程序将中文日期输出为2001-12-23,并很好解决了“十”的问题,如“十一”和“二十一”中“十”的处理!稍加修改可改为函数。
<?
$str="二零○一年十二月二十三日";
echo $str."<p>";
$flag=0;
$cn=array("一","二","三","四","五","六","七","八","九","十","零","○");
$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<count($cn))
   {
     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++;
   }
}
?> 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50