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

时间:2016-10-10 05:36:17

标签: php preg-replace

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

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

1 个答案:

答案 0 :(得分:4)

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

  1. 仅限空格,请使用str_replacestr_replace()
  2. $chosen_string = str_replace(' ', '', $chosen_string);

    1. 对于所有空格,请使用preg_replacepreg_replace()
    2. $chosen_string = preg_replace('/\s+/', '', $chosen_string);

      备忘单参考:

      enter image description here