Capture output of php script into a variable?


I'm trying to compare the features of PHP to ASP.NET.  One thing I do all the time in 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:

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,
LVL 33
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:

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

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

Might want to chime in on this one too if you'd like,
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I use that method a lot in my web pages, works fine.

Glad I could help
All Courses

From novice to tech pro — start learning today.