Loading...

PHP數字轉國字...

Temperature: 0 °C

ChungChung
author_tools

什麼鬼...客戶系統的需求竟然有一個數字要轉成國字....

數字轉國字...數字轉國字...就是要把10000轉成壹萬...@@

從來沒想過會有這樣的東西....

知道概念應該是用陣列的方式來取代...

就像之前有寫過星期的1234567要取代成一二三四五六日是一樣的道理...

在這裡用了懶人寫程式的方式......Google...

沒想到還真的有...

Google真是太神了........總之整理了一下...把不需要的部份修改了一下

就成了以下的函式...

function ch_num_change($num,$mode=true) {
$char = array("零","壹","貳","叁","肆","伍","陸","柒","捌","玖");
$dw = array("","拾","佰","仟","","萬","億","兆");
$retval = "";
if($mode)
preg_match_all("/^0*(d*).?(d*)/",$num, $ar);
else
preg_match_all("/(d*).?(d*)/",$num, $ar);
if($ar[1][0] != "") {
$str = strrev($ar[1][0]);
for($i=0;$i<strlen($str);$i++) {
$out[$i] = $char[$str[$i]];
if($mode) {
$out[$i] .= $str[$i] != "0"? $dw[$i%4] : "";//以萬為單位
if($str[$i]+$str[$i-1] == 0)
$out[$i] = "";
if($i%4 == 0)
$out[$i] .= $dw[4+floor($i/4)];
}
}
$retval = join("",array_reverse($out)) . $retval;
}
return $retval;
}

接著是引用這個函式...
echo ch_num_change("10000"); //印出來壹萬的字串..

附上原出處:Url link

台北市松山區八德路四段650號 Go

https://innstory.com/story-PHP數字轉國字-313
寫程式筆記

Prev
 今天很適合喝一杯

Next
使用jquery_animate達到動態效果 

Nearby Attractions

台北市松山區八德路四段650號-Nearby Attractions

  • 司法大廈 Go
  • 前美國大使官邸 Go
  • 國立臺灣大學日式宿舍─翁通楹... Go
  • 芝山岩隘門 Go
  • 殷海光故居 Go
  • 長老教會北投教堂 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

PHP 時間時區修正

PHP 時間時區修正

一般來說...PHP取得的時間,是格林威治的時間: 但如果要將時間調成臺灣的時區,或其他時區的話,必...

使FCKeditor所上傳的圖檔檔名亂數化

使FCKeditor所上傳的...

編輯"../fckor/or/filemanager/connectors/php/com...

在PHP裡面如何做到基本的SQL injection防禦?

在PHP裡面如何做到基本的S...

資訊安全一直是很頭痛的問題....我一直以來也在尋找最好的方式... 但在尋找的過程中...至少也得...

Recommended reading

Other stories happened at this address

鍾姓三嘗祠堂

鍾姓三嘗祠堂

chung 接下這個專案時....其實心裡有些感觸...... 隨著年齡越來越大....對於血緣的部...

RewriteRule仿靜態連結

RewriteRule仿靜態...

前幾天寫了關於頁面導向位置的定義。https://innst...

Mysql最怕就是手賤

Mysql最怕就是手賤

今天我手賤了眼盲了@@... 錯把delete當成UPDATE....啃!!今天下午超不順的... ...

圖型插件Elastislide

圖型插件Elastislid...

teach Elastislide是一款好用的圖形插件......

Google map 功能導入

Google map 功能導...

blogmap 寫故事還是得有地圖才好厚! 前幾天,sam同我說有一個客戶有Google map的需...

ありがとう 大橋卓彌

ありがとう 大橋卓彌

我,離家多年...歲了..一直在做著遙不可及的夢,走著未知的路...沒什麼長進。 希望有一天,我也可...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format