ItSolutionStuff.com

How to Remove White Space from String in PHP?

By Hardik Savani • May 14, 2024
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: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get First and Last Character from String in PHP?

Read Now →

How to Get Last Character from String in PHP?

Read Now →

How to Get First Character from String in PHP?

Read Now →

How to Remove Last Character from String in PHP?

Read Now →

How to Remove First Character from String in PHP?

Read Now →

PHP Remove First and Last Character from String Example

Read Now →

PHP Remove Whitespace from Beginning and End of String Example

Read Now →

How to Check Query Execution Time in PHP?

Read Now →

PHP CURL Post Request with Parameters Example

Read Now →

PHP JQuery Chosen Ajax Autocomplete Example

Read Now →

How to Get Folder Path from File Path in PHP?

Read Now →

How to access PHP variables in JQuery?

Read Now →