Intercept require output in PHP or execute PHP in file_get_contents

… So we’re introducing a plan-intercept. Only immediately prepare a report that the plan-interception no results.
The Lord of the Rings: the Two Towers

In order to load the contents of a file and display it in a certain place of a Web page, you can use file_get_contents, but if the file loaded in this way will contain PHP code, it is not processed.
For the PHP code to execute in a dynamically loaded file, you can use the command require, but it outputs the result instantly, and if we pre-generate the output into a variable, this method is also not suitable… Or does it fit?

In PHP there is a set of commands to buffer output to enable the output buffer by using the ob_start() command. After that, we call require and collect the result in the variable with the command ob_get_clean();

function GetPHP($file_name){
    ob_start();
    require( $file_name );
    return ob_get_clean();
}

Here is a function that returns the result of executing a PHP script in a variable.

echo GetPHP('some-file.php');