S
S
Shimpanze2017-10-02 06:51:06
JavaScript
Shimpanze, 2017-10-02 06:51:06

PHP: Is it possible to process content received with the require function?

Good afternoon!
Can you please tell me if it's possible to process the content received with the require() function with your own function? Something like this: Tried like this:
sobstvennayaFunctsiya( require( 'content.php' ) );

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

... doesn't work either.
PS I am aware of the function file_get_contents, but it is not suitable if the inserted file contains php tags - they are simply escaped and the php code is not executed. And I need to get the already executed html and php code and process it with my own function.
Many thanks to everyone who will respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2019-06-22
@IwanQ

https://codepen.io/anon/pen/NZpoqQ?editors=1010
-
https://developer.mozilla.org/en-US/docs/Web/API/W...

L
Lander, 2017-10-02
@Shimpanze

Well, either as Camaro67 wrote, or just_hank_moody already said about buffering.

ob_start();
require(<файл>);
$content = ob_get_contents();
ob_clean();

echo $content; //в $content лежит содержимое <файл>

And any eval() is potentially vulnerable and its use is highly discouraged. Although, of course. purely academic option working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question