Blueblazer Blueblazer - 1 year ago 92
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);

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download