This is what you need:

ob_start();
echo $content;
$content = ob_get_clean();
// do something about $content
echo $content;