我想用没有空格的空白替换所选用户名。
preg_replace("[ ]", "", $username);
答案 0 :(得分:4)
您可以按照下面提供的任何方法删除字符串中的空格。
str_replace
:str_replace() $chosen_string = str_replace(' ', '', $chosen_string);
preg_replace
:preg_replace() $chosen_string = preg_replace('/\s+/', '', $chosen_string);
备忘单参考: