Problems with php printing with file_get_contents (); - mpdf

0

I am using mpdf to generate a report, and for this I'm calling another file .php that owns the information, through file_get_contents(); .

You are viewing the contents of this file, it just does not read php correctly, as an example of the code: <?php echo 'Olá'; ?> , everything just appears instead of just Hello.

Could anyone help me?

    
asked by anonymous 21.01.2016 / 11:49

1 answer

1

file_get_contents does not interpret PHP code. It just reads a file as a string and stores it in memory.

In order for the php code to be interpreted and you can see what was printed by echo you should use the include/require function.

include will immediately execute echo , which will be printed on the browser output, not on the PDF.

To solve this problem, you will probably have to capture the buffer and output, like this:

ob_start();

include 'php_que_quero_incluir.php';

$saida = ob_get_clean();
    
21.01.2016 / 11:55