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函式紀錄

常常忘記,只得紀錄下來...... AddSlashes: 字符串加入斜線。 binhex: 二進位...

PHP數字1000分位逗號分隔函數number_format()

PHP數字1000分位逗號分...

有時候我們必需將數字加上每三個位數加上一個逗號(千分位),例如變成,,我雖不常用...但偶爾要用到時...

Android Studio 2.3 隨機改變背景顏色

Android Studio...

class55 開始學習APP 其實我照著工具書上的方式總是在宣告變數時會產生問題~ 例如工具書上寫...

Recommended reading

Other stories happened at this address

Photoshop 曲線文字建置

Photoshop 曲線文字...

Photoshop一直都是很強悍的繪圖軟體。 裡頭的【鋼筆工具】,可以拉貝茲曲線的.... 我剛開始...

圖型插件Elastislide

圖型插件Elastislid...

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

行事曆功能導入

行事曆功能導入

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

今晚,來盤鯊魚(炒)芹菜。

今晚,來盤鯊魚(炒)芹菜。

已經忘了從什麼時候開始會煮菜的... 我煮的菜,叫不出什麼響亮的名字、外表樸實、味道是傳承小時候家裡...

Mysql最怕就是手賤

Mysql最怕就是手賤

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

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