21

I have function that has :

ob_start();
//Include of some files
$content = ob_get_contents();
ob_end_clean();

Now in those includes is another function that uses the same code, and they seem to conflict. Is it possible to use them like this?

somerandomusername
  • 1,993
  • 4
  • 23
  • 55

2 Answers2

24

Try using output buffer like this :

ob_start();
// your includes
echo ob_get_clean();

Use this in all of your includes, and you will not get any errors

d4rkpr1nc3
  • 1,817
  • 13
  • 16
  • 2
    I had similar problem but mistakenly used ob_clean() instead ob_end_clean() - be aware of their difference! – besimple Sep 15 '15 at 21:22
10

Output buffering should be stackable, you just need to match ob_start with ob_end_clean. See http://php.net/ob_start

Michal Čihař
  • 9,799
  • 6
  • 49
  • 87