1

Is it possible to get file output buffer string to execute the file in background instead of including it?

Right now this is the only way which I have seen. See code below;

ob_start();
include($file);
$html = ob_get_contents();
ob_end_clean();

But I have list of files which I don't want to include. I just want to execute the file in background process for getting output buffer string.

Can anyone please help me on it?

Thanks Smac

Saeed Afzal
  • 368
  • 1
  • 5
  • 18
  • Maybe just fetch the contents ? [`file_get_contents()`](http://php.net/file_get_contents) – Darren Mar 05 '15 at 05:14
  • It does not execute the php tags. I need a string with php executed tags. I also have checked for eval() already. It does not work perfect. – Saeed Afzal Mar 05 '15 at 05:41

1 Answers1

1

If your file is php you need to use include.For multiple files you can use function like this I found here

function include_multi($files) {
    $files = func_get_args();
    foreach($files as $file)
        include($file);
}

And call it with

include_multi("one.php", "two.php", ..);

Also If you want plain file contents(No need to execute file) you can use file_get_contents or readfile

Community
  • 1
  • 1
Sachin Joshi
  • 119
  • 5
  • I have html source file with php tags. If I include file then html will be render in web browser which I don't want. I just want to get buffer string of each file. So can you please advice me the best solution for this? – Saeed Afzal Mar 05 '15 at 05:38
  • You can use file_get_contents for that. – Sachin Joshi Mar 05 '15 at 05:50
  • file_get_contents() only returns the string. Does not execute the php tags. – Saeed Afzal Mar 05 '15 at 05:57
  • For that you have to do some string manipulation like getting contents between and then use [eval](http://php.net/manual/en/function.eval.php) to execute that php code. – Sachin Joshi Mar 05 '15 at 06:03
  • I also have already tried eval and done in this way. I found the another approach. I'm testing it now. I think I have fixed it. I will answer shortly. But thanks for your kind help. Appreciated!. – Saeed Afzal Mar 05 '15 at 06:22