Marty
Marty

Reputation: 39466

PHP file_get_contents with a php file

I'm using file_get_contents() to merge a template and separate content and output them together as a page.

The problem I'm having is that if either of these files have a PHP statement,

<?php
    echo "example";
?>

The PHP isn't actually run, and the statement just seems to be part of the markup:

enter image description here

I thought at first that the PHP at the file I'm loading wouldn't be run first, but then I made a test page with the following:

<?php
    echo file_get_contents("http://stackoverflow.com");
?>

And uploaded it here to see that it works fine (processes the PHP first).

Should I be using a different function maybe?

Upvotes: 1

Views: 923

Answers (1)

Leonid Shevtsov
Leonid Shevtsov

Reputation: 14189

You just need to include() the PHP file.

Be wary of the security concerns.

If you want to capture the file's output, use output buffering.

Upvotes: 4

Related Questions