|
Author |
Message |
phpDude
Junior WebHelper
Joined: 28 Apr 2002
Posts: 2
|
Posted:
Sun Apr 28, 2002 9:31 pm (22 years ago) |
|
Hi all,
I have a php file that generates a table that I would like to save into a variable inside another php file. How would I do this? the include function seems to just execute the file and output it so I can't seem to save the output to a variable. I thought that maybe exec or passthru might work, but they don't.
Any ideas? The reason I need to be able to save the output to a variable is that my system uses a templating system and I need to save to a variable that the template can access.
I'm pretty sure there is a command in php for doing this, but could not find anything in the manual or through searching.
thanks. |
|
|
|
|
robert
Junior WebHelper
Joined: 28 Mar 2002
Posts: 20
Location: Heythuysen, The Netherlands
|
Posted:
Mon Apr 29, 2002 5:02 pm (22 years ago) |
|
I'm not sure about this, but i think you just should save the output in a variable in the "other" script (the script that's generating the table). Remember not to print the output in the table-generating-script, cuz then it would be saved to a variable AND it'll be printed.
hope this works out. |
________________________________ Friends help you move. Real friends help you move bodies. |
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Mon Apr 29, 2002 5:59 pm (22 years ago) |
|
You could make your table creator into a function, then it would only out put when you called it.
edit: I just reread the question this probably isn't relevant
Code: | <?
//file1.php
function create_table() {
?>
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>
<?
}
?> |
Code: | <?
//file2.php
include("file1.php");
?>
<html>
<head>
<title></title>
</head>
<body>
<?
create_table();
?>
</body>
</html> |
|
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Apr 29, 2002 6:40 pm (22 years ago) |
|
Is this what you want?
Code: | include.php:
$variable="blabla";
index.php:
include ("include.php");
echo $variable; |
|
________________________________
|
|
|
|
phpDude
Junior WebHelper
Joined: 28 Apr 2002
Posts: 2
|
Posted:
Mon Apr 29, 2002 9:50 pm (22 years ago) |
|
I had a php file (two.php) that generated a table and echoed html output. I needed to store this html output in a variable for a template system. Problem with calling include(two.php) inside one.php was that it started generating html start page stuff and echoed the output into the html instead of the variable. I was looking for an easy way to save the output, but was unsuccessful. I really needed to do this right away, so after I posted the message I hacked a quick, but dirty solution which is essentially what Robert mentioned. Inside two.php now I store the html into a variable $table_html instead of echoing it. Inside one.php I include two.php and then use the variable $table_html. Hopefully they will include a function for this in the future since I had to go in the file and change all the echos. Another way that might work is to use output buffering and save the buffer into a variable, but I did not try this as I was unsure of how it would affect the output buffering already in use in one.php and the file was short enough that I only had to spend a few minutes fixing it.
It looks like others have need for this also. I was browsing around and interestingly found a page that faces the problem of including a file that echos html output inside another. You can see the problems at this site. http://www.marksportal.net/dev/cal_demo/
Thanks for all who replied. |
|
|
|
|
jayant
Team Member
Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India
|
Posted:
Wed May 01, 2002 7:06 pm (21 years, 12 months ago) |
|
I am sure this will work:
Code: |
<?php
// get a web page into an array and print it out
$fcontents = file ('http://idya.resource-locator.com/');
while (list ($line_num, $line) = each ($fcontents)) {
echo "<b>Line $line_num:</b> " . htmlspecialchars ($line) . "<br>\n";
}
// get a web page into a string
$fcontents = join ('', file ('http://idya.resource-locator.com/'));
?>
|
Good Luck! |
________________________________ Jayant Kumar
Member of the 4WebHelp Team
Nibble Guru - Computing Queries Demystified
GZip/ Page Compression Test |
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.140862 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |