user2467577
user2467577

Reputation:

PHP file_get_contents function

I am developing php-based websites. When I try to load a file from the same directory using file_get_contents, the server did return some string, but php code of that file are also returned. I want the file after compiled by php, not the native code. How can I fix this problem?

Upvotes: 0

Views: 129

Answers (4)

Peter Brand
Peter Brand

Reputation: 624

When wanting use the contents of a PHP file for example to create a pdf, and you want the parsed output, not the code, one can trap the output buffer of the include operation.

ob_start();
include 'something.php';
$html = ob_get_clean();
ob_end_clean();
$this->mpdf->WriteHTML($html);

Upvotes: 0

Harm Wellink
Harm Wellink

Reputation: 226

Try to use the include() function instead.

Upvotes: 0

user
user

Reputation: 545

call the file_get_contents on the url and not on the path

Upvotes: 0

Nil'z
Nil'z

Reputation: 7475

Use this instead:

include "file.php";

Upvotes: 1

Related Questions