-3

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

preg_replace("[ ]", "", $username);
Stephen Docy
  • 4,698
  • 7
  • 17
  • 31
Blueblazer172
  • 551
  • 2
  • 14
  • 43

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
  • 3,937
  • 2
  • 13
  • 32