0

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?

3
  • getting file contents from url may be? I mean like file_get_contents("www.yoursite.com/page1.php") Commented Jul 15, 2013 at 12:36
  • Are you looking for an opcode version of the PHP file, or the output produced if it's run? Commented Jul 15, 2013 at 12:36
  • 1
    RTFM! php.net/manual/en/function.include.php Commented Jul 15, 2013 at 12:37

4 Answers 4

1

Use this instead:

include "file.php";
Sign up to request clarification or add additional context in comments.

2 Comments

why include? he wants the output of the file not the phpscript itself
See, thats what he wanted. @Akam
0

call the file_get_contents on the url and not on the path

Comments

0

Try to use the include() function instead.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.