replace multiple spaces with a single space in a string in php - PHP Views : 1466
Tagged in : PHP
0 0
Send mail
We will use ereg_replace to replace multispace (multiple spaces) in a string with one single space

function multiple_space_replace($string)
{
// using ereg_replace to replace space, tabs and newline in a given string
$str = ereg_replace("[ \t\n\r]+", " ", $string);
return $str;
}

$string = "This is testing multi space replace";
$newstr = multiple_space_replace($string);

echo $newstr;
?>


Result:
This is testing multi space replace
By rajesh, On - 2010-01-03



    Login to add Comments .