Overflowing
Overflowing

Reputation: 1

Can PHP grab its own full output and process it?

I've already made a function which takes an input string representing a HTML document and validates it locally.

I'm trying to auto-validate my own PHP-generated webpages with it.

Can PHP store its own full output in a $string so that it can send this to my validator function in the very end, after all output is done?

Upvotes: 0

Views: 17

Answers (1)

Alfredo Rahn Linde
Alfredo Rahn Linde

Reputation: 73

Yup!

https://www.php.net/manual/en/function.ob-start.php

https://www.php.net/manual/en/function.ob-get-contents.php

Basically:

<?php

ob_start();

echo "Hello ";

$out1 = ob_get_contents();

echo "World";

$out2 = ob_get_contents();

ob_end_clean();

var_dump($out1, $out2);
?>

Upvotes: 1

Related Questions