网上找了很多的php消去全角空格的方法,但是我这都没有效果,最后想出的方法是选择用js在表单提交之前删除。方法是:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form action="first.php" method="get">
<input type="text" id="input" oninput="getValue();" onporpertychange="getValue();">
<input type="hidden" id="text"name="text">
<input type="submit">
</form>
<script type="text/javascript">
function getValue(){
// 获取input输入框的值
var value=document.getElementById("input").value;
// 转换好内容放到新输入框中(也可以放入旧输入框)
var othre=value.replace(/[\t\r\f\n\s]*/g, "");
document.getElementById("text").value=othre;
}
</script>
</body>
</html>
后端只需要GET出数据。
<?php
echo $_GET["text"];
?>
输入框效果:
输出结果:
也是给自己做个记录,希望能帮助到你。