I use this code and pattern:
preg_replace('/\\s+/', ' ',$data)
$data = 'This is a Text
and so on Text text on multiple lines and with whitespaces';
$data= preg_replace('/\\s+/', ' ',$data);
echo $data;
You may test this on http://writecodeonline.com/php/