Normalize spaces between words in PHP

$title = 'The Institute for Pure and            Applied Mathematics        ';
// Normalize space between words.
$patterns = array("/\s+/", "/\s([?.!])/");
$replacer = array(" ", "$1");
$title = preg_replace($patterns, $replacer, $title);

Result:

The Institute for Pure and Applied Mathematics

 

********************************** ************************* ************************ **************** ****************** *********** ************** ************* ************ *************