如何来根据数字显示大写汉字 比如在文本框中输入123 单击提交按钮就会显示壶百贰拾叁元等等,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有php语言写,你能给我说怎么变吗,谢谢啦 Javascript是首选, 客户端都能做的东西何必麻烦服务端? 网上这样的代码应该有的,把它转为js就成了,大致的做法是把这些东西搞一个数组里边 ,算法怎么写的,我就不献丑了。 给你参考下,没经过完整测试,不带小数点,最多到兆<?php/** * 将数字金额转换为中文 * * @param integer $num 数值 * @param bool $big 是否返回大写中文 * @return string */function int2chn($num,$big = true){ if ($big) { $arr_chn = explode(',','零,壹,贰,叁,肆,伍,陆,柒,捌,玖'); $arr_pos = explode(',','圆,拾,佰,仟,萬,拾,佰,仟,亿,拾,佰,仟,兆'); } else { $arr_chn = explode(',','零,一,二,三,四,五,六,七,八,九'); $arr_pos = explode(',','元,十,百,千,万,十,百,千,亿,十,百,千,兆'); } $str = ''; $num = strval(intval($num)); for ($pos=strlen($num)-1;$pos>=0;$pos--) { $n = $num{$pos}; if ($n == 0 && $pos%4 > 0) { $str = $arr_chn[$n].$str; } else { $str = $arr_chn[$n].$arr_pos[strlen($num)-1-$pos].$str; } } $str = preg_replace('/零+/u','零',$str); $str = preg_replace('/零([萬万亿兆圆元])/u','$1',$str); return $str;}echo int2chn(123456789,false)."\n";echo int2chn(123006780);?> php我不会,我写了一个C# C/S 版的,只是语法可能不一样而已,要是不介意的话可以看看,或是加我的QQ给你传,QQ号我主页上有下载源代码:http://download.csdn.net/source/1910845 可以用jquery发送ajax请求,代码如下:<script type="text/script" /><document.ready(function(){ var num = $('.input_num'); //input_num为input框的class名 $.ajax({ type:"POST", data:"num="+num, url:"http://4楼函数所在地址", success:function(){ window.location = window.location.href; } });});</script 漏了点东西:<script type="text/script" /><document.ready(function(){ var num = $('.input_num').val(); //input_num为input框的class名 $.ajax({ type:"POST", data:"num="+num, url:"http://4楼函数所在地址", success:function(){ window.location = window.location.href; } });});</script JS版:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="editplus" /> <meta name="author" content="JnKc" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> *{font-size:12px;} </style></head><body><input type="text" name="price" onchange="show(this.value);" onkeyup="show(this.value);" /> <span id="price_show"></span><script type="text/javascript">function show($num){ document.getElementById('price_show').innerHTML = int2chn($num);}function int2chn($num){ if (isNaN($num)) return '请输入整数'; var $arr_chn = '零,壹,贰,叁,肆,伍,陆,柒,捌,玖'.split(','); var $arr_pos = '圆,拾,佰,仟,萬,拾,佰,仟,亿,拾,佰,仟,兆'.split(','); $str = ''; $num = parseInt($num).toString(); $arr_num = $num.match(/\d/g).reverse(); for (var $i=0;$i<$arr_num.length;$i++){ $n = $arr_num[$i]; if ($n == 0 && $i%4 > 0) { $str = $arr_chn[$n] + $str; } else { $str = $arr_chn[$n] + $arr_pos[$i] + $str; } } $str = $str.replace(/零+/g,'零'); $str = $str.replace(/零([萬亿兆圆])/g,'$1'); return $str;}</script></body></html> VBS版:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="editplus" /> <meta name="author" content="JnKc" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> *{font-size:12px;} </style></head><body><form method="post" action=""> <input type="text" name="price" /></form><script type="text/vbscript">Sub price_onchange() Dim num : num = Document.forms(0).price.value & "" Dim aryChn : aryChn = Split("零,壹,贰,叁,肆,伍,陆,柒,捌,玖",",") Dim aryPos : aryPos = Split("圆,拾,佰,仟,萬,拾,佰,仟,亿,拾,佰,仟,兆",",") Dim tmpS,sNum,I sNum = "" For I = 0 To Len(num)-1 tmpS = num Mod 10 If tmpS = 0 And (I Mod 4) > 0 Then sNum = aryChn(tmpS) & sNum Else sNum = aryChn(tmpS) & aryPos(I) & sNum End If num = num \ 10 Next Dim oRegExp Set oRegExp = New RegExp oRegExp.Multiline = True oRegExp.IgnoreCase = True oRegExp.Global = True oRegExp.Pattern = "零+" sNum = oRegExp.Replace(sNum,"零") oRegExp.Pattern = "零([萬亿兆圆])" sNum = oRegExp.Replace(sNum,"$1") Set oRegExp = Nothing MsgBox sNumEnd Sub</script></body></html> 列表批量分页-打印。如何实现? 关于PHP并发的问题 麻烦高手帮忙还原下这段ZEND 这个语句是不是不行? update 语句奇怪的问题. 请问,Call to undefined function mssql_connect() 是哪儿错了?,怎么解决?谢谢! 为什么有的系统中不直接输出HTML 而是通过调用JS输出,有什么好处么? 关于正则表达式的小问题! 可是输入我自己的IP却不行? CURL后的结果解析成数组问题 关于mysql默认值的问题 PHP-GTK真的还是在玩具时代吗?
/**
* 将数字金额转换为中文
*
* @param integer $num 数值
* @param bool $big 是否返回大写中文
* @return string
*/
function int2chn($num,$big = true)
{
if ($big) {
$arr_chn = explode(',','零,壹,贰,叁,肆,伍,陆,柒,捌,玖');
$arr_pos = explode(',','圆,拾,佰,仟,萬,拾,佰,仟,亿,拾,佰,仟,兆');
} else {
$arr_chn = explode(',','零,一,二,三,四,五,六,七,八,九');
$arr_pos = explode(',','元,十,百,千,万,十,百,千,亿,十,百,千,兆');
}
$str = '';
$num = strval(intval($num));
for ($pos=strlen($num)-1;$pos>=0;$pos--) {
$n = $num{$pos};
if ($n == 0 && $pos%4 > 0) {
$str = $arr_chn[$n].$str;
} else {
$str = $arr_chn[$n].$arr_pos[strlen($num)-1-$pos].$str;
}
}
$str = preg_replace('/零+/u','零',$str);
$str = preg_replace('/零([萬万亿兆圆元])/u','$1',$str);
return $str;
}
echo int2chn(123456789,false)."\n";
echo int2chn(123006780);
?>
php我不会,我写了一个C# C/S 版的,只是语法可能不一样而已,要是不介意的话可以看看,或是加我的QQ给你传,QQ号我主页上有
下载源代码:http://download.csdn.net/source/1910845
可以用jquery发送ajax请求,代码如下:<script type="text/script" />
<document.ready(function(){
var num = $('.input_num'); //input_num为input框的class名
$.ajax({
type:"POST",
data:"num="+num,
url:"http://4楼函数所在地址",
success:function(){
window.location = window.location.href;
}
});
});
</script
<document.ready(function(){
var num = $('.input_num').val(); //input_num为input框的class名
$.ajax({
type:"POST",
data:"num="+num,
url:"http://4楼函数所在地址",
success:function(){
window.location = window.location.href;
}
});
});
</script
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="editplus" />
<meta name="author" content="JnKc" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
*{font-size:12px;}
</style>
</head>
<body>
<input type="text" name="price" onchange="show(this.value);" onkeyup="show(this.value);" /> <span id="price_show"></span>
<script type="text/javascript">
function show($num){
document.getElementById('price_show').innerHTML = int2chn($num);
}
function int2chn($num)
{
if (isNaN($num)) return '请输入整数';
var $arr_chn = '零,壹,贰,叁,肆,伍,陆,柒,捌,玖'.split(',');
var $arr_pos = '圆,拾,佰,仟,萬,拾,佰,仟,亿,拾,佰,仟,兆'.split(',');
$str = '';
$num = parseInt($num).toString();
$arr_num = $num.match(/\d/g).reverse();
for (var $i=0;$i<$arr_num.length;$i++){
$n = $arr_num[$i];
if ($n == 0 && $i%4 > 0) {
$str = $arr_chn[$n] + $str;
} else {
$str = $arr_chn[$n] + $arr_pos[$i] + $str;
}
}
$str = $str.replace(/零+/g,'零');
$str = $str.replace(/零([萬亿兆圆])/g,'$1');
return $str;
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="editplus" />
<meta name="author" content="JnKc" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
*{font-size:12px;}
</style>
</head>
<body>
<form method="post" action="">
<input type="text" name="price" />
</form>
<script type="text/vbscript">
Sub price_onchange()
Dim num : num = Document.forms(0).price.value & ""
Dim aryChn : aryChn = Split("零,壹,贰,叁,肆,伍,陆,柒,捌,玖",",")
Dim aryPos : aryPos = Split("圆,拾,佰,仟,萬,拾,佰,仟,亿,拾,佰,仟,兆",",")
Dim tmpS,sNum,I
sNum = ""
For I = 0 To Len(num)-1
tmpS = num Mod 10
If tmpS = 0 And (I Mod 4) > 0 Then
sNum = aryChn(tmpS) & sNum
Else
sNum = aryChn(tmpS) & aryPos(I) & sNum
End If
num = num \ 10
Next
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Multiline = True
oRegExp.IgnoreCase = True
oRegExp.Global = True
oRegExp.Pattern = "零+"
sNum = oRegExp.Replace(sNum,"零")
oRegExp.Pattern = "零([萬亿兆圆])"
sNum = oRegExp.Replace(sNum,"$1")
Set oRegExp = Nothing
MsgBox sNum
End Sub
</script>
</body>
</html>