How do you get final outputed HTML in PHP?

The typical way to get “the entire page worth of HTML” is to use the template_redirect hook, it’s often used for “run-time find & replace” methods. If I ever need to use it, I just use it in an Anonymous Function.

add_action( 'template_redirect', function(){
    ob_start( function( $buffer ){
        // Do whatever to $buffer - it contains the entire page's HTML output

        return $buffer;
    });
});

error code: 523