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

清除網頁暫存(no cache)

清除網頁暫存(no cach...

pexelsphoto5 在製作專案時,有沒有試過JS 或 CSS 明明就已經更新了~ 但頁面卻像鬼...

動態留言功能調整

動態留言功能調整

guestmap55 最近改進了朋友動態的發文方式.... 一開始在功能方面加上了googlemap...

Google map 功能導入

Google map 功能導...

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

Recommended reading

Other stories happened at this address

行事曆功能導入

行事曆功能導入

cc Innstory有行事曆囉! 我試著把Innstory當作是我的筆記本,將生活發生的故事紀錄下...

紙娃娃

紙娃娃

flower 紙娃娃其實是我給這個專案的名稱.... 因為做這功能時讓我想起來小時候看鄰居家小女孩玩...

Responsive Web Design使用CSS3的Media Queries進行自適應網頁設計

Responsive Web...

智慧型手持裝置(手機、平板)已是非常普及的日常生活必需品。 所以現在,在開發系統時客戶都會詢問是否支...

ありがとう 大橋卓彌

ありがとう 大橋卓彌

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

你是不是像我就算受了冷漠,也不放棄自己想要的生活。

你是不是像我就算受了冷漠,也...

累了就該充電一下,聽首好歌... 好歌總能激勵人心。 不寫,就會就永遠寫不完......寫了,遲早有...

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

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

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

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