Blueblazer Blueblazer - 1 month ago 5
PHP Question

How to replace a whitespace in choosen username?

I want to replace a choosen username with blankspaces with no spaces.

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


You can follow any of the methods provided below for the removal of the white spaces from the string.

  1. For just spaces, use str_replace: str_replace()

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

  1. For all whitespace, usepreg_replace: preg_replace()

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

Cheat Sheet Reference:

enter image description here