?
Solved

Capture output of php script into a variable?

Posted on 2006-10-26
3
Medium Priority
?
1,615 Views
Last Modified: 2011-09-20
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
Comment
Question by:raterus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17811864

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

0
 
LVL 33

Author Comment

by:raterus
ID: 17811971
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17813160
I use that method a lot in my web pages, works fine.

Glad I could help
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question