473,394 Members | 1,739 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,394 software developers and data experts.

capturing print output of function to variable

Hi all,

I have a function, say:

function printTable($Variables)
{
?>
<table>
<tr><td>Your name is</td></tr>
<tr><td>
<?php
print $Name;
print "</td></tr></table>";
}

(Obviously not my exact function, but a simple one to demonstrate my
needs... The function I have inherited is much bigger with much mixed php
and html like the example)

It is currently used to print the same data table on many pages.
I have been asked to have the system send this data table by email, so
what I want to do is run the function, but send the output of the function
to a variable, in the same way that print_r($arr,1) will return the output
instead of printing it.

Is this possible?

Cheers,

Ben
Jun 25 '06 #1
4 2336
Ben Holness wrote:
Hi all,

I have a function, say:

function printTable($Variables)
{
?>
<table>
<tr><td>Your name is</td></tr>
<tr><td>
<?php
print $Name;
print "</td></tr></table>";
}

(Obviously not my exact function, but a simple one to demonstrate my
needs... The function I have inherited is much bigger with much mixed php
and html like the example)

It is currently used to print the same data table on many pages.
I have been asked to have the system send this data table by email, so
what I want to do is run the function, but send the output of the function
to a variable, in the same way that print_r($arr,1) will return the output
instead of printing it.

Is this possible?

Cheers,

Ben

Try output buffering.

ob_start();

callMyNiftyFunction();

$contents = ob_get_contents();

ob_end_clean();
Jun 25 '06 #2
Joe Estock wrote:
Ben Holness wrote:
Hi all,

I have a function, say:

function printTable($Variables)
{
?>
<table>
<tr><td>Your name is</td></tr>
<tr><td>
<?php
print $Name;
print "</td></tr></table>";
}

(Obviously not my exact function, but a simple one to demonstrate my
needs... The function I have inherited is much bigger with much mixed php
and html like the example)

It is currently used to print the same data table on many pages.
I have been asked to have the system send this data table by email, so
what I want to do is run the function, but send the output of the
function
to a variable, in the same way that print_r($arr,1) will return the
output
instead of printing it.

Is this possible?

Cheers,

Ben

Try output buffering.

ob_start();

callMyNiftyFunction();

$contents = ob_get_contents();

ob_end_clean();

Jun 25 '06 #3
Ben Holness wrote:
Hi all,

I have a function, say:

function printTable($Variables)
{
?>
<table>
<tr><td>Your name is</td></tr>
<tr><td>
<?php
print $Name;
print "</td></tr></table>";
}

I have been asked to have the system send this data table by email, so
what I want to do is run the function, but send the output of the function
to a variable, in the same way that print_r($arr,1) will return the output
instead of printing it.


Like this?

function printTable($Variables, $return = false)
{
$tableHtml = "
<table>
<tr><td>Your name is</td></tr>
<tr><td>$Name</td></tr>
</td></tr></table>";

if($return){
return $tableHtml;
} else {
echo $tableHtml;
return;
}
}
Jun 25 '06 #4
> Try output buffering.

ob_start();

callMyNiftyFunction();

$contents = ob_get_contents();

ob_end_clean();


Perfect! Thanks,

Ben
Jun 26 '06 #5

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

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
5
by: Mike | last post by:
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...
2
by: Tim Williams | last post by:
----- Original Message ----- From: "Tim Williams" <listserver@tdw.net> > ----- Original Message ----- > From: "Steve Holden" <steve@holdenweb.com> > Yeah, I did wonder about changing the...
1
by: ebobnar | last post by:
I'm sure you all have seen how using the src argument in a script tag is essentially the same as including the body of the script within your page. For example: <script type="text/javascript"...
5
by: Fly Girl | last post by:
Gurus needed! I'm trying to use a Word class object in order to capture events in Word. Here's what I have, but the event code appWord_BeforeDocumentSave... doesn't ever fire. In a Class Module...
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. ...
5
by: Luigi | last post by:
Hi to all! I'd like to execute an external program capturing the stdout/stderr messages at "real-time". I mean that I don't want to wait for the end of the process. If I write a code like this:...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.