How to Remove White Space from String in PHP?

By Hardik Savani November 5, 2023 Category : PHP

Hey Folks,

If you need to see an example of how to remove space from string in php. you will learn how to remove all whitespace from a string in php. you can understand a concept of remove whitespace from string php. This article goes in detailed on remove space from string in php. Here, Create a basic example of delete space from string in php.

Sometimes we require to remove white space from given string. So at that time you can delete spaces from string using str_replace() of core php. str_replace() will help to replace whitespace that way we can remove. you can do it from bellow example.




/* Declare string variable */

$myString = "Welcome to!";

/* remove white space from string in PHP */

$newString = str_replace(' ', '', $myString);

/* Echo resulted string */

echo $newString;



I hope it can help you...

Tags :