Codice PHP:
function callback($buffer) {
  return (
htmlspecialchars(str_replace(" "," ",str_replace("\t","   ",$buffer))) . "
\n"
);

Dove "\t" sono le tabulazioni;