|
|
replace multiple spaces with a single space in a string in php - PHP
|
Views : 1466
|
|
Tagged in : PHP
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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 |
|
|
|