Problems with php printing with file_get_contents(); - mpdf

Asked

Viewed 261 times

0

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

It is displaying the contents of this file, only it does not read php correctly, as example the code: <?php echo 'Olá'; ?>, just appears everything, instead of just showing up Hello.

Could someone help me?

  • Post the code you’re using so we can help.

  • I answered, but I have a slight impression that the question is duplicated.

  • 1

    @Andrébaill I don’t even think you need code.

1 answer

1

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

So that the php code is interpreted and you can see what was printed by echo should use the function include/require.

The include shall immediately execute the echo, being the same printed in the browser output, and not in the PDF.

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

ob_start();

include 'php_que_quero_incluir.php';

$saida = ob_get_clean();
  • You can use it to file_get_contents() to run a url, it is processed and the result is stored in a variable. If you had the question code it would be easier :P.

  • It makes sense @rray, but from his description I’ve already detected what the mistake was.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.