replace multiple spaces with single space php code example
Example 1: php replace two spaces with one
$output = preg_replace('!\s+!', ' ', $input);
Example 2: php replace multiple spaces end chrters to one
$string = preg_replace('/[\s$@_*]+/', '_', $string);