function replaceNbspWithSpace($content){
$string = htmlentities($content, null, 'utf-8');
if (strpos($string, ' ') !== false) {
$content = str_replace(" ", " ", $string);
$content = html_entity_decode($content);
}elseif(strpos($content, ' ') !== false
) {
$content = str_replace(" ", " ", $content);
$content = html_entity_decode($content);
}
return $content;
}
Anschließend kann man durch trim, ltrim oder rtrim die Leerzeichen entfernen.