replace more than one space with one 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);