轉(zhuǎn)換中文日期的PHP程序
更新時(shí)間:2006年10月09日 00:00:00 作者:
本程序?qū)⒅形娜掌谳敵鰹?001-12-23,并很好解決了“十”的問題,如“十一”和“二十一”中“十”的處理!稍加修改可改為函數(shù)。
<?
$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++;
}
}
?>
<?
$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++;
}
}
?>
相關(guān)文章
Breeze 文章管理系統(tǒng) v1.0.0正式發(fā)布
Breeze 文章管理系統(tǒng) v1.0.0正式發(fā)布...2006-12-12
php入門學(xué)習(xí)知識(shí)點(diǎn)二 PHP簡(jiǎn)單的分頁(yè)過程與原理
PHP簡(jiǎn)單的分頁(yè)過程與原理分析,主要是讀取數(shù)據(jù)庫(kù)的時(shí)候,如果數(shù)據(jù)庫(kù)內(nèi)容較多,我們就需要分頁(yè)顯示。2011-07-07
php學(xué)習(xí)之運(yùn)算符相關(guān)概念
php學(xué)習(xí)之運(yùn)算符相關(guān)概念,學(xué)習(xí)php的朋友可以參考下。2011-06-06

