Remove Unnecessary Spaces Function with PHP

If you want to reduce multiple spaces at the beginning, end and middle of string values to a single space, you can use this function. In short, it deletes all unnecessary spaces.


function replaceSpace($string)
	$string = preg_replace("/\s+/", " ", $string);
	$string = trim($string);
	return $string;

$string = '     test             test             ';
print replaceSpace($string);

There are no comments, make the firs comment