Prevent double space when entering username

后端 未结 2 1029
夕颜
夕颜 2021-01-07 08:32

When users register to my website I want to allow them to use spaces in their username, but only one space per word.

My current code:

$usor = $_POST[         


        
2条回答
  •  被撕碎了的回忆
    2021-01-07 09:22

    Use the following:

    $username = preg_replace('/[\s]+', " ", $usor);
    

    That will replace multiple spaces with a single space.

提交回复
热议问题