<?php
//
// == Super Trim ==============================================================
// Autor: Tripa Seca (fosfozol@yahoo.com.br)
//
// Vers�o: v0.0 @ 28/Fev/2002
//         Desenvolvimento do script em si.
//
// Oque � isso?: As vezes vc pode ter problema com espa�oes, antes, depois ou
//               no meio da string, eliminios com o super trim
//
//
// Copyright: GNU General Public License
//            Modifique a vontade para adaptar a sua necessidade.
// ============================================================================
//

function ts_supertrim($txt){
  $txt = trim($txt);
  for ($i = 0; $i < substr_count($txt, "  "); $i++) {
    $txt = str_replace("  ", " ", $txt);
    $txt = str_replace("   ", " ", $txt);
  }
  //$txt = strtolower($txt); //converte para lowercase
  return $txt;
}

$string_de_um_usuario_estupido = "                           carro                 de                    galinha         �             v�cuo                ";

?>
<body nowrap>
Antes:<br>
<?php echo "<p>&quot;".str_replace(" ", "&nbsp;", $string_de_um_usuario_estupido)."&quot;</p>"?>
<br>
<br>
<b>Depois:</b><br>
<?php echo "<p>&quot;".ts_supertrim($string_de_um_usuario_estupido)."&quot;</p>";?>
</body>