<?php $a = 'a b c d e'; $pattern = '([\s\n]+)'; $replace = ' '; $a = preg_replace($pattern, $replace, $a); echo $a."\n"; ?>