01.
<?
02.
function
numtothaistring(
$num
)
03.
{
04.
$return_str
=
""
;
05.
$txtnum1
=
array
(
''
,
'หนึ่ง'
,
'สอง'
,
'สาม'
,
'สี่'
,
'ห้า'
,
'หก'
,
'เจ็ด'
,
'แปด'
,
'เก้า'
);
06.
$txtnum2
=
array
(
''
,
'สิบ'
,
'ร้อย'
,
'พัน'
,
'หมื่น'
,
'แสน'
,
'ล้าน'
);
07.
$num_arr
=
str_split
(
$num
);
08.
$count
=
count
(
$num_arr
);
09.
foreach
(
$num_arr
as
$key
=>
$val
)
10.
{
11.
if
(
$count
> 1 &&
$val
== 1 &&
$key
==(
$count
-1))
12.
$return_str
.=
"เอ็ด"
;
13.
else
14.
$return_str
.=
$txtnum1
[
$val
].
$txtnum2
[
$count
-
$key
-1];
15.
}
16.
return
$return_str
;
17.
}
18.
function
numtothai(
$num
)
19.
{
20.
$return
=
""
;
21.
$num
=
str_replace
(
","
,
""
,
$num
);
22.
$number
=
explode
(
"."
,
$num
);
23.
if
(sizeof(
$number
)>2){
24.
return
'รูปแบบข้อมุลไม่ถูกต้อง'
;
25.
exit
;
26.
}
27.
$return
.= numtothaistring(
$number
[0]).
"บาท"
;
28.
$stang
=
intval
(
$number
[1]);
29.
if
(
$stang
> 0)
30.
$return
.= numtothaistring(
$stang
).
"สตางค์"
;
31.
else
32.
$return
.=
"ถ้วน"
;
33.
return
$return
;
34.
}
35.
36.
?>