How to Remove White Space from String in PHP?

By Hardik Savani May 14, 2024 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.

Example:

index.php

<?php

/* Declare string variable */

$myString = "Welcome to ItSolutionStuff.com!";

/* remove white space from string in PHP */

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

/* Echo resulted string */

echo $newString;

?>

Output:

WelcometoItSolutionStuff.com!

I hope it can help you...

Tags :
Shares