[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1624
  • Last Modified:

Capture output of php script into a variable?

Hi,

I'm trying to compare the features of PHP to ASP.NET.  One thing I do all the time in ASP.net is execute another page, grab the content, and use it in a variable.  I'm trying to figure out how to do this in PHP.

Lets say I have the following two files:
main.php
subcontent.php

In main.php, I want to execute subcontent.php, and grab the output into a variable.  I'd rather not have to mess with URL's, which most of the examples I see involve doing.  I just want to execute subcontent.php, and get all the output to a variable.  This is not the same thing as using "include"!

Thanks for any help,
0
raterus
Asked:
raterus
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

ob_start();
include "subcontent.php";
$variable = ob_get_contents();
ob_end_clean();

0
 
raterusAuthor Commented:
That definitely looks good to me, Thanks!

Might want to chime in on this one too if you'd like,
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_22038506.html
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I use that method a lot in my web pages, works fine.

Glad I could help
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now