这里简单的介绍了关于PHP解决input输入多个空格只显示一个的问题,我们利用了chr(32)来替换成html空格符,实例代码如下:
- <body>
- <form id=form1 name=form1 method=post action=>
- <label for=textfield></label>
- <input type=text name=txt id=txt />
- <input type=submit name=button id=button value=提交 />
- </form>
- </body>
- </html>
- <?
- if( $_POST )
- {
- $txt = $_POST['txt'];
- echo $txt.'<br />';
- echo str_replace(chr(32),' ',$txt);
- }
- ?>