Hello is there a way to take the content of a php file while processing the php code in it? I need to include a code into another page but I need to print the content it in a specific position.
If I use include the code will be printed before the html tag of course cause it's processed before the page, but if I use file_get_contents the content is taken in the page but if I have some php tags I'll get those too as plain text.
Thank you.
EDIT: sorry guys seems like I was drunk while I was writing. I corrected.
I have an engine that processes the page contents, puts them into a variable and then print them in a specific position within the html page. In the engine I need to "embed" the code of other "static" pages that could have some php tags. If I use file_get_contents I will get the content as plain text (with php tags not parsed) if I use include it just won't work cause it's not the function for it. So I what I need is to embed the PROCESSED code into the engine (as ready-to-be-printed HTML).
The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.
file — Reads entire file contents into an array of lines. file_get_contents — Reads entire file contents into a string.
The file_get_contents function takes the name of the php file and reads the contents of the text file and displays it on the console. get the contents, and echo it out.
You can use an output buffer to include a PHP file but save the resulting output for later use instead of printing it immediately to the browser.
ob_start();
include('path/to/file.php');
$output = ob_get_contents();
ob_end_clean();
// now do something with $output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With