Replacing Spaces with Underscores

前端 未结 12 553
北海茫月
北海茫月 2020-11-30 20:14

I have a PHP Script that users will enter a name like: Alex_Newton,

However, some users will use a space rather than an underscore, so my question is:

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 21:10

    As of others have explained how to do it using str_replace, you can also use regex to achieve this.

    $name = preg_replace('/\s+/', '_', $name);
    

提交回复
热议问题