0

Hi I have one file where I'm using file_get_contents to get another php file - the target file should run some php and output an HTML table, which it does if I just load it in the browser, however when I use file_get_contents to retrieve it, the php code is retrieved, not the html table.

Should I be using something different than file_get_contents?

What should I be using?

Andrew Samuelsen
  • 5,325
  • 9
  • 47
  • 69
  • possible duplicate of [How to run php code from file_get_contents or file in a function](http://stackoverflow.com/questions/8472783/how-to-run-php-code-from-file-get-contents-or-file-in-a-function) – mario Jun 11 '12 at 21:22
  • have you considered an ajax call? – jlasarte Jun 11 '12 at 21:23
  • 1
    See the manual on what [`file_get_contents()`](http://php.net/file_get_contents) is for. Use [`include()`](http://php.net/include) as usual if you want the contained code evaled. – mario Jun 11 '12 at 21:24
  • @mario, thanks - I have an issue w/headers colliding from the target and the source. The source is going to output an .xls file, and the target includes some wordpress junk that insists on its own headers. Are there any other work arounds w/ob? – Andrew Samuelsen Jun 11 '12 at 21:25
  • @mno4k, unfortunetally I can't have any other (client side) markup on the source page as it is going to output an .xls file – Andrew Samuelsen Jun 11 '12 at 21:26
  • Use an `iframe` then. Also where does the xls file come from? Didn't your question say html table? – mario Jun 11 '12 at 21:27
  • @mario ya its an html table with .xls headers. How would you use an iframe? – Andrew Samuelsen Jun 11 '12 at 21:29
  • If it's html with xls headers, then it's no xls at all. Stop trying to trick applications with invalid headers. That's not what they are for. – mario Jun 11 '12 at 21:32
  • @mario, ok say I were to use phpexcel to properly create an xls file - the problem is having 1 page w/phpexcel headers and another w/wordpress headers... – Andrew Samuelsen Jun 11 '12 at 21:33
  • Won't work. HTML is HTML. You can't mix in binary content anyway, much less two distinct pairs of headers. Why would you think so? – mario Jun 11 '12 at 21:35
  • @mario - ok, say I change the output of the target too - the problem is that I need the output of the php file included, or file_get_contented or somehow retrieved from the source page - include doesn't work becuase the target has header that mustn't be included. I need JUST the content – Andrew Samuelsen Jun 11 '12 at 21:37
  • * [Headers already sent](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) * read all of it. / or the first link given / or if you meant actual html content with "headers", but forgot to mention it, adapt your output logic to not output the html preamble when a variable/flag is present. – mario Jun 11 '12 at 21:38
  • @mario - thanks. in other words - not possible – Andrew Samuelsen Jun 11 '12 at 21:52

1 Answers1

0

use include("filename.php") instead of file_get_contents

file_get_contents is for jut returning the contents of a file.

Habeeb
  • 166
  • 13