PHP normaliza caracteres de espaço em branco

<?php

function normalizeWhitespaceCharacters( $string )
{
    $stepOne = htmlentities($string);
    $stepTwo = trim(preg_replace('/(&nbsp;)+|\s\K\s+/','', $stepOne));
    $final = html_entity_decode($stepTwo);
    return $final;
}
Baba of Arus