Solved

Capture output of php script into a variable?

Posted on 2006-10-26
3
1,588 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
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 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 142

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now