How to remove all spaces from string in php?
In this post, use the PHP preg_replace() function to strip or remove all whitespaces inside a string.
1. Code:
<?php
function removeAllWhiteSpace($string){
$string = trim($string);
$string = preg_replace('/\s+/', '', $string);
return $string;
}
$str = "Soltuts.com
is providing PHP
tutorials";
echo(removeAllWhiteSpace($str));
?>
2. Example:
Input:
$str ="Soltuts.com
is providing PHP
tutorials";
Output:
Soltuts.comisprovidingPHPtutorials