PHP: is it possible to process content received via the require function?

Good day!

Please tell me whether it is possible to process the content received using the function require(), use own function? Something like this:

sobstvennayaFunctsiya( require( 'content.php' ) );

I tried this:

$p = function() {
 return require('content.php');
}
sobstvennayaFunctsiya echo( $p );


... also not working.

PS I know about the function file_get_contents, but it is not suitable if the inserted file has the php tags - they are simply screened and php code is not executed. And I need to get filled with html and php code and handle its own function.

Thank you to all who respond.
June 14th 19 at 21:06
2 answers
June 14th 19 at 21:08
Solution
Well it's either what was written or said about bufferization.
ob_start();
require(<file>);
$content = ob_get_contents();
ob_clean();

echo $content; //the $content lies with the content of <file>

And any eval () is potentially vulnerable to use it is not recommended. Though, of course. purely academically, the option working.
June 14th 19 at 21:10
Solution
No, not the require Function only attaches the file and returns back a string.

In this case it is better to read about bufferization in php.

Turn on output buffering at the beginning of the script, at the end of the execution of the script to read into a string buffer and then process it function.

Or file_get_contents plus function eval();
Or file_get_contents plus function eval();

Dangerous option. But I use it because you know its dangerous places. - rhianna_Fee commented on June 14th 19 at 21:13

Find more questions by tags PHP