473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Capturing data from another php file

I'm trying to capture data that is created by launching a php file,
for example the last 10 posts in a message forum. If last10.php is
called directly in your browser you'll see hyperlinks to the last 10
posts. This file is located in /home/mydomain/last10.php .

Now I'm trying to capture that data in a template in a CMS I'm using
where you can launch php scripts. I'm just unsure how one can "run"
last10.php and capture the stream into a variable and then include
that variable to be outputted in another template. As long as I
capture the stream, that variable can simply be placed in another
template so I'm not so concerned about that.

Now I'm familiar with includes and requires, but this doesn't really
"launch" the file, it only includes the items so that you can use the
variables from my understanding. The problem is that I need the whole
stream from the last10.php to be captured into one variable that will
then print out this html that was output.

Learning this stuff is truly amazing... I hope to quit my day job. :)
Thanks... Mike

Jul 17 '05 #1
5 1615
NC
Mike wrote:

I'm trying to capture data that is created by launching
a php file, for example the last 10 posts in a message
forum. If last10.php is called directly in your browser
you'll see hyperlinks to the last 10 posts. This file
is located in /home/mydomain/last10.php .


There are at least two ways of doing it.

1. Use output buffering. Additionally, you might want
to wrap the include() call into a function to prevent
accidental modification of variables in the calling
script by last10.php:

function get_last_10() {
ob_start();
include('last10.php');
return ob_get_clean();
}

echo get_last_10(); // output last 10 posts
$last10 = get_last_10(); // capture the posts into a variable

2. Capture the output of last10.php using file system
functions and the HTTP wrapper. To simply output
the last 10 posts you could do:

readfile('http://localhost/last10.php');

To capture the last 10 posts into a variable, you
can do:

$last10 = file_get_contents('http://localhost/last10.php');

Cheers,
NC

Jul 17 '05 #2
On 19 Mar 2005 02:01:14 -0800, "NC" <nc@iname.com> wrote:
Mike wrote:

I'm trying to capture data that is created by launching
a php file, for example the last 10 posts in a message
forum. If last10.php is called directly in your browser
you'll see hyperlinks to the last 10 posts. This file
is located in /home/mydomain/last10.php .


There are at least two ways of doing it.

1. Use output buffering. Additionally, you might want
to wrap the include() call into a function to prevent
accidental modification of variables in the calling
script by last10.php:

function get_last_10() {
ob_start();
include('last10.php');
return ob_get_clean();
}

echo get_last_10(); // output last 10 posts
$last10 = get_last_10(); // capture the posts into a variable

2. Capture the output of last10.php using file system
functions and the HTTP wrapper. To simply output
the last 10 posts you could do:

readfile('http://localhost/last10.php');

To capture the last 10 posts into a variable, you
can do:

$last10 = file_get_contents('http://localhost/last10.php');

Cheers,
NC


SUPERB!!!!! I tried like crazy to use the output buffering method you
mentioned. For some reason include produced nothing (blank) and trying
to use require produced a completely blank page and I'm guessing it
wouldn't load.

However, using the readfile method was perfect! Thanks so much!!!
That's one that I hadn't seen used. :)

Mike

Jul 17 '05 #3
NC
Mike wrote:

I tried like crazy to use the output buffering method you
mentioned. For some reason include produced nothing (blank)
and trying to use require produced a completely blank page
and I'm guessing it wouldn't load.


Most likely, you didn't specify the correct file name/path.
In case of an error, include() generates a warning, while
require() halts the script...

Cheers,
NC

Jul 17 '05 #4
On Sat, 19 Mar 2005 03:00:08 -0500, Mike wrote:
I'm trying to capture data that is created by launching a php file,
for example the last 10 posts in a message forum. If last10.php is
called directly in your browser you'll see hyperlinks to the last 10
posts. This file is located in /home/mydomain/last10.php .

Now I'm trying to capture that data in a template in a CMS I'm using
where you can launch php scripts. I'm just unsure how one can "run"
last10.php and capture the stream into a variable and then include
that variable to be outputted in another template. As long as I
capture the stream, that variable can simply be placed in another
template so I'm not so concerned about that.

Now I'm familiar with includes and requires, but this doesn't really
"launch" the file, it only includes the items so that you can use the
variables from my understanding.


Then your understanding needs changing.

include and require allow different scripts to share the same program code.

common.inc.php

<?php

function HelloWorld() {
return "Hello World<br>\n";
}

?>

a.php

<?php

include('common.inc.php');

echo HelloWorld();

?>

b.php

<?php

include('common.inc.php');

for($i=0;$i<10;$i++)
{
echo HelloWorld();
}

?>

You should not be looking at including last10.php into your program but
the code that last10.php uses to generate it's output.

It is likely to be calling a database script that returns a result set
which can be far more easily used than the output from a web page.

Jul 17 '05 #5
"Mike" <tk********************@yahSPAMoo.com> wrote in message
news:r0********************************@4ax.com...
On 19 Mar 2005 02:01:14 -0800, "NC" <nc@iname.com> wrote:
Mike wrote:

I'm trying to capture data that is created by launching
a php file, for example the last 10 posts in a message
forum. If last10.php is called directly in your browser
you'll see hyperlinks to the last 10 posts. This file
is located in /home/mydomain/last10.php .


There are at least two ways of doing it.

1. Use output buffering. Additionally, you might want
to wrap the include() call into a function to prevent
accidental modification of variables in the calling
script by last10.php:

function get_last_10() {
ob_start();
include('last10.php');
return ob_get_clean();
}

echo get_last_10(); // output last 10 posts
$last10 = get_last_10(); // capture the posts into a variable

2. Capture the output of last10.php using file system
functions and the HTTP wrapper. To simply output
the last 10 posts you could do:

readfile('http://localhost/last10.php');

To capture the last 10 posts into a variable, you
can do:

$last10 = file_get_contents('http://localhost/last10.php');

Cheers,
NC


SUPERB!!!!! I tried like crazy to use the output buffering method you
mentioned. For some reason include produced nothing (blank) and trying
to use require produced a completely blank page and I'm guessing it
wouldn't load.


Is the include() statement inside a function per NC's suggestion? If so, it
could be a variable scoping issue. Say you have some config variables
defined globally and functions that make use of them:

$db_user = 'dingo';
$db_pass = '4t3_my_b4by';

function connect_to_db() {
global $db_user, $db_pass
// ...
}

When the include() happens inside a function, those variable will no longer
be global, so functions that depend on them will cease to work.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jerrygarciuh | last post by:
Hello, I have a client who has decided to output the OO PHP/mySQL site I have made for them onto a cd. I realize that $html = include('somefile.php'); gets 1 for success as its return value....
33
by: Joerg Schuster | last post by:
Hello, Python regular expressions must not have more than 100 capturing groups. The source code responsible for this reads as follows: # XXX: <fl> get rid of this limitation! if...
2
by: Chris Windsor | last post by:
I hope the following describe what I'm trying to do: I have created a tool to be used by product analysts when studying different cell phone designs. Part of the tool is a set of 11 forms on a...
3
by: sparks | last post by:
They have a new data collection station. The people here are using access 97.... This third party site will only post data back to us when we do this. ...
1
by: Jonah Olsson | last post by:
Hello, I'm trying to build an "add-on" to an already existing custom web user control. The old control collects some user data and saves it to a database. The new control should collect some...
10
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
6
by: Ed Leafe | last post by:
I've been approached by a local business that has been advised that they need to start capturing and archiving their instant messaging in order to comply with Sarbanes-Oxley. The company is largely...
0
by: Buglish | last post by:
Hi, Task : -Capture a HTML table with use of regular expression from a text string buffer(entire document). –Pass it to another function to create a multi dimension array out of it. - Pass it...
2
by: jallam | last post by:
Hi, I have a Python script to upload the Invoice data which is in .csv file to OTM (GLOG) system. I'm running this script using the command(given below) using a shell script and capturing the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.