本文主要是介绍PHP实现分离金额和其他内容便于统计计算,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
得到的结果可以粘贴到excel计算
<?php
if($_GET["x"] == "cha"){
$tips = isset($_POST['tips']) ? $_POST['tips'] : '';
$pattern = '/(\d+\.\d+|\d+)/';
$result = preg_replace($pattern, "\t\${1}\t", $tips);
echo "<h2><strong>数字前后+制表符</strong>:</h2>\r\n";
echo "<textarea>$result</textarea>";
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>数字前后+制表符</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<script type="text/javascript">
console.log("问题反馈电话:","15058593138");
console.log("问题反馈邮件:","admin@12391.net");
function $(objId){
return document.getElementById(objId);
}
function loadcha(xid) {
var xmlhttp;
var Stxt= "nums=aa";
Stxt+="&tips="+ encodeURIComponent($("tips").value);
//$("tips").innerHTML = "正在加载...";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var btxt = xmlhttp.response;
if(btxt == "err01"){ $("tipx").innerHTML = "!"; return false;}
$('tipx').innerHTML = xmlhttp.response;
}
}
xmlhttp.open("POST", "?x=cha&tt="+Math.random(), true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(Stxt);
}</script>
<style>
div,#tipx{display:block;width:99.7%;border:0;margin-top:5px;}
textarea{display:block;width:99.7%;border:1px solid #ccc;height:160px;}
table{margin:20px auto;border-left:1px solid #a2c6d3;border-top:3px solid #0180CF;font-size:12px;width:99.7%;}
table td{border-right:1px solid #a2c6d3;border-bottom:1px solid #a2c6d3;padding:2px;word-wrap:break-word;word-break:break-all;}
td{min-width:30px;max-width:490px;}
#submit{ height:35px;}
</style>
</head>
<body>
<form class="form" id="form" method="POST" act="?act=cha" >
<h3>数字前后+制表符</h3>
<p>便于分隔出来粘贴到Excel计算</p>
<textarea id="tips">
张三10元
李四1.1元
王五0.1元
</textarea><input type="button" id="submit" value="提交发送" onclick="loadcha('xid')">
<div id="tipx"></div></form>
</body>
</html>
这篇关于PHP实现分离金额和其他内容便于统计计算的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!