A parte casi particolari dovrebbe andare:

Codice PHP:
<?php
$str    
'<div class="prova">ciao mondo</div>';
$out    '';
$in_tag false;

for (
$x 0$x strlen($str); $x++) {
    if (
$str[$x] == '<'$in_tag true;
    if (
$str[$x] == '>'$in_tag false;
    if ((
$str[$x] == ' ' && $in_tag) or $str[$x] != ' ') {
        
$out .= $str[$x];
    }
}

echo 
$out;
?>