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

Mysql 查詢時間區間是否包含特定日期

Mysql 查詢時間區間是否...

這其實只是一個簡單的問題,以前並不常用... 但這陣子寫的案子比較偏系統面,這樣的查詢問題變多了@@...

臺北典藏植物園

臺北典藏植物園

5年寒假前,綠的學校安排了戶外教學,地點臺北典藏植物園。 和同學們一起搭了火車,搭了公車,走路,最後...

Apache無法執行.htaccess?

Apache無法執行.hta...

pexelsphoto5 首先.htaccess是在Apache HTTP Server服務器架設下...

Recommended reading

Other stories happened at this address

定義404頁面

定義404頁面

什麼是頁面? HTTP 或Not Found錯誤訊息是HTTP的其中一種「標準回應訊息」(HTTP狀...

熊出沒!

熊出沒!

前幾天,花了些時間重新設計了innstory裡的代表頭像... facechange 想說把一開始的...

愛情無全順

愛情無全順

我覺得還蠻好笑的... 我好像也是宅男一族厚....其實感情這種事真的是說不準的.... 天想到.....

用distinct在MySQL中查詢多條不重複記錄值

用distinct在MySQ...

select *, count(distinct name) from table group by...

RewriteRule仿靜態連結

RewriteRule仿靜態...

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

蘑菇醬麵

蘑菇醬麵

據我所知...老婆大人在嫁給我之前是顯少進廚房的 上個星期天....老婆說想煮蘑菇醬麵 於是.......

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