2

Alright,

Heres the thing. I have a (paid for) shopping cart, which I am currently in the process of jazzing up with jquery and css and whatever else to make it look and work much nicer than it currently is.

Anyway. In order to use their database and their functions etc, I need to include their file at the beginning of the webpage. I have put it in a

<div style="display:none;">

But of course any output is still written to the browser. its not alot, but I would prefere to have NO div and NO output, but i still want it to perform it's calculations. Its 5000 line PHP file and Its too complicated to go through and edit out the bits I dont want.

is there a clever way, that I can include the file but specify if I want anything written to page when including it?

I knows it's a bit of a bodge, I hope i've explained myself, if anyone can help please let me know.

Thanks.

Chud37
  • 4,907
  • 13
  • 64
  • 116
  • You have paid for a five thousand line PHP script. Can't the author make it not output anything when not requested? – CodeCaster Jun 29 '12 at 12:57
  • 1
    This shopping app was bought before I joined the company. It's saving me from writing a completely new shopping and database management system, so I am happy to use it. I did think of asking them but technically I am not really using their script the right way; I think they would just say no. – Chud37 Jun 29 '12 at 13:00
  • They'll happily do it, but happily charge you for it, too :] – Konerak Jun 29 '12 at 13:00

2 Answers2

9

You can use output buffering to catch output into a variable instead of sending it to the browser:

ob_start();
require(...);
$data = ob_get_clean();

Note the use of require instead of include. That is because I personally think that the script should crash when hitting an include error, not continue as if nothing is wrong.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
1

Check out ob_start() and ob_end_clean(). They allow you to capture the output and dump it which should fix your problem. You might also want to talk to your vendor about creating a non-outputing version of their software which is really what it should be doing (I know preaching to the chorus).

I never actually knew of a valid reason to use ob-end-clean until now. :-)

Scott Keck-Warren
  • 1,894
  • 3
  • 18
  • 33