如何替换所选用户名中的空格?

How to replace a whitespace in chosen username?

我想用没有空格的空格替换选定的用户名。

preg_replace("[ ]", "", $username);

您可以按照下面提供的任何方法从字符串中删除空格。

  1. 对于空格,使用 str_replacestr_replace()

$chosen_string = str_replace(' ', '', $chosen_string);

  1. 对于所有空格,使用preg_replacepreg_replace()

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

作弊Sheet参考: