程序员人生 网站导航

php解决input输入多个空格只显示一个的问题

栏目:php教程时间:2014-03-08 14:31:01

这里简单的介绍了关于php解决input输入多个空格只显示一个的问题,我们利用了chr(32)来替换成html空格符,实例代码如下:

  1. <body> 
  2. <form id="form1" name="form1" method="post" action=""> 
  3.   <label for="textfield"></label> 
  4.   <input type="text" name="txt" id="txt" /> 
  5.   <input type="submit" name="button" id="button" value="提交" /> 
  6. </form> 
  7. </body> 
  8. </html> 
  9. <? 
  10. if( $_POST ) 
  11. { 
  12.  $txt = $_POST['txt']; 
  13.  echo $txt.'<br />'; 
  14.  echo str_replace(chr(32),'&nbsp;',$txt); 
  15. } 
  16. ?> 
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐