WordPress Version: 6.1
/**
* Normalizes EOL characters and strips duplicate whitespace.
*
* @since 2.7.0
*
* @param string $str The string to normalize.
* @return string The normalized string.
*/
function normalize_whitespace($str)
{
$str = trim($str);
$str = str_replace("\r", "\n", $str);
$str = preg_replace(array('/\n+/', '/[ \t]+/'), array("\n", ' '), $str);
return $str;
}