Solved

Capture output of php script into a variable?

Posted on 2006-10-26
3
1,607 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 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

690 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