$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:
$title => The Institute for Pure and Applied Mathematics