-3

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

preg_replace("[ ]", "", $username);
Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
Blueblazer172
  • 588
  • 2
  • 15
  • 44

1 Answers1

3

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

Naresh Kumar P
  • 4,127
  • 2
  • 16
  • 33