如何替换所选用户名中的空格?
How to replace a whitespace in chosen username?
我想用没有空格的空格替换选定的用户名。
preg_replace("[ ]", "", $username);
您可以按照下面提供的任何方法从字符串中删除空格。
- 对于空格,使用
str_replace
:str_replace()
$chosen_string = str_replace(' ', '', $chosen_string);
- 对于所有空格,使用
preg_replace
:preg_replace()
$chosen_string = preg_replace('/\s+/', '', $chosen_string);
作弊Sheet参考:
我想用没有空格的空格替换选定的用户名。
preg_replace("[ ]", "", $username);
您可以按照下面提供的任何方法从字符串中删除空格。
- 对于空格,使用
str_replace
:str_replace()
$chosen_string = str_replace(' ', '', $chosen_string);
- 对于所有空格,使用
preg_replace
:preg_replace()
$chosen_string = preg_replace('/\s+/', '', $chosen_string);
作弊Sheet参考: