轉(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)文章
php利用cookie實(shí)現(xiàn)訪問次數(shù)統(tǒng)計(jì)代碼
php 利用cookie實(shí)現(xiàn)訪問次數(shù)統(tǒng)計(jì),需要的朋友可以參考下。2011-05-05php中一個(gè)完整表單處理實(shí)現(xiàn)代碼
《PHP5與MySQL5 Web開發(fā)技術(shù)詳解》第5章主要講的是表單——處理用戶輸入,本小節(jié)主要講的是一個(gè)完整表單處理。2011-11-11php學(xué)習(xí)之 認(rèn)清變量的作用范圍
變量的存在有著它的生命周期,我們可以讓它存在于一個(gè)小的函數(shù)內(nèi)部,也可讓它存在于整個(gè)程序當(dāng)中。對(duì)于一般情況下聲明的變量,我們稱之為局部變量,只能在當(dāng)前程序段中存在,而使用$globals聲明出來的變量則是在當(dāng)前頁面整個(gè)程序當(dāng)中都會(huì)有效。2010-01-01php addslashes 函數(shù)詳細(xì)分析說明
PHP 中的 addslashes 函數(shù) addslashes -- 字符串加入斜線。2009-06-06