5+ PHP Blank Space Remover Programs

This post contains a total of 5+ PHP Blank Space Remover Program Examples with Source Code. All these Blank Space Remover Programs are used to remove Blank / White Space from Strings, and these programs are made using PHP.

You can use the source code of these examples with credits to the original owner.

Related Posts

PHP Blank Space Remover Programs

1. By Fekri Jamil

Made by Fekri Jamil. Simple PHP Program to remove blank empty spaces from a input string. Source

input : ab c  d e fgh i  j kl mn  opqr  stuvwxyz
output : abcdefghijklmnopqrstuvwxyz
$input_string = "ab c  d e fgh i  j kl mn  opqr  stuvwxyz";
$result_string = str_replace(' ', '', $input_string );

echo "<pre>";
echo "<strong>Remove Spaces from a String</strong> <br/><br/>";
echo "input : " . $input_string . "<br/>";
echo "output : " . $result_string . "<br/>";
echo "</pre>";

2. By Bnmx

Made by Bnmx. Basic program to Remove Spaces from a String. Source

Input Message : My Name is Behnam
The string without any spaces : MyNameisBehnam
$msg="My Name is Behnam"; //change string here
echo "Input Message : $msg ";
echo "<br>";
echo "The string without any spaces : "
     ,str_replace(' ','',$msg);   
// you can use str_split() too

3. By Nishan

Made by Nishan. This program will remove the white spaces between the string that is entered through “$word” . Source

  $word="hello good morning everyone";
  echo(implode(explode(" ",$word)));  

4. By Roronoa

Made by Roronoa. Source

a b c d
$input = "a b c d" ;
$result = str_replace(" ", "", $input);
echo $result;

5. By Bart Android

Made by Bart Android. Source

Remove spaces from a string:
Input : Yeah I can code, a bit!
Output : YeahIcancode,abit!
  $str = "<br>Yeah I can code, a bit!";
  echo "<em>Remove spaces from a string:</em> $str";
  $expl = explode(" ",$str);
  foreach ($expl as $x) {
      echo $x;

6. By Flying raah

Made by Flying raah. Basic PHP program to remove white space from text and number string. Source

Before: 1 2 3 a b c
After: 123abc
$text = "1 2 3 a b c";

function str_rmspaces($string = "") {
    return str_replace(" ", "", $string);

print "Before: ".$text."<br>";
print "After: ".str_rmspaces($text);