How to take output from an include, and embed it into a variable?
How to take output from an include, and embed it into a variable?
am 08.09.2009 06:35:45 von Rob Gould
I have an invoice table that is drawn on a number of pages, so I have
all the logic in an include-file like this:
include "invoicetable_bottom.php";
However, now I'm needing to take the output from that include file and
pass it as an email. To do that, I need to somehow take the output
from this include file and get it into a variable somehow. Is there a
simple way to do this?
Something like: $emailtcontent = include "invoicetable_bottom.php"?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to take output from an include, and embed it into a
am 08.09.2009 06:37:06 von Eddie Drapkin
On Tue, Sep 8, 2009 at 12:35 AM, Rob Gould wrote:
> I have an invoice table that is drawn on a number of pages, so I have all
> the logic in an include-file like this:
>
> include "invoicetable_bottom.php";
>
>
> However, now I'm needing to take the output from that include file and pa=
ss
> it as an email. Â To do that, I need to somehow take the output from =
this
> include file and get it into a variable somehow. Â Is there a simple =
way to
> do this?
>
> Something like: Â $emailtcontent =3D include "invoicetable_bottom.php=
"?
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Use output buffering and capture:
http://us3.php.net/manual/en/book.outcontrol.php
ob_start();
include 'stuff_that_makes_html.php';
$contents =3D ob_get_clean();
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to take output from an include, and embed it into a variable?
am 23.09.2009 12:35:42 von Puiu Hrenciuc
Hi,
The simplest way (actually the single way I know :) ) would be to
capture the output using output buffering functions, something like this:
// start output buffering
ob_start();
// include the file that generates the HTML (or whatever content)
include "....";
// get output buffer content
$output=ob_get_contents();
// clean output buffer and stop buffering
ob_end_clean();
// the content generated in the included file is now in $output variable
// use it as you consider fit
..........
Regards,
Puiu
Rob Gould wrote:
> I have an invoice table that is drawn on a number of pages, so I have
> all the logic in an include-file like this:
>
> include "invoicetable_bottom.php";
>
>
> However, now I'm needing to take the output from that include file and
> pass it as an email. To do that, I need to somehow take the output from
> this include file and get it into a variable somehow. Is there a simple
> way to do this?
>
> Something like: $emailtcontent = include "invoicetable_bottom.php"?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re: How to take output from an include, and embed it intoa variable?
am 23.09.2009 12:45:15 von Mert Oztekin
--_000_E2C046087E10D943811A0BD0A4E8316D1B57CD11E8ankaraanado lu_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Output buffering will do it.
Also I am not sure but did you try retrieving content with fopen() ?
Something like
$file =3D 'invoicetable_bottom.php';
fopen("http://yoursite.com/folder/$file","r");
http://tr.php.net/function.fopen
worth trying. Easier than output buffering
-----Original Message-----
From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
Sent: Wednesday, September 23, 2009 1:36 PM
To: php-general@lists.php.net
Subject: [PHP] Re: How to take output from an include, and embed it into a =
variable?
Hi,
The simplest way (actually the single way I know :) ) would be to
capture the output using output buffering functions, something like this:
// start output buffering
ob_start();
// include the file that generates the HTML (or whatever content)
include "....";
// get output buffer content
$output=3Dob_get_contents();
// clean output buffer and stop buffering
ob_end_clean();
// the content generated in the included file is now in $output variable
// use it as you consider fit
..........
Regards,
Puiu
Rob Gould wrote:
> I have an invoice table that is drawn on a number of pages, so I have
> all the logic in an include-file like this:
>
> include "invoicetable_bottom.php";
>
>
> However, now I'm needing to take the output from that include file and
> pass it as an email. To do that, I need to somehow take the output from
> this include file and get it into a variable somehow. Is there a simple
> way to do this?
>
> Something like: $emailtcontent =3D include "invoicetable_bottom.php"?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
________________________________
Bu mesaj ve ekleri, mesajda g?nderildi?i belirtilen ki?i/ki?ilere ?zeldir v=
e gizlidir. Size yanl??l?kla ula?m??sa l?tfen g?nderen kisiyi bilgilendirin=
iz ve mesaj? sisteminizden siliniz. Mesaj ve eklerinin i?eri?i ile ilgili o=
larak ?irketimizin herhangi bir hukuki sorumlulu?u bulunmamaktad?r. ?irketi=
miz mesaj?n ve bilgilerinin size de?i?ikli?e u?rayarak veya ge? ula?mas?nda=
n, b?t?nl???n?n ve gizlili?inin korunamamas?ndan, vir?s i?ermesinden ve bil=
gisayar sisteminize verebilece?i herhangi bir zarardan sorumlu tutulamaz.
This message and attachments are confidential and intended for the individu=
al(s) stated in this message. If you received this message in error, please=
immediately notify the sender and delete it from your system. Our company =
has no legal responsibility for the contents of the message and its attachm=
ents. Our company shall have no liability for any changes or late receiving=
, loss of integrity and confidentiality, viruses and any damages caused in =
anyway to your computer system.
--_000_E2C046087E10D943811A0BD0A4E8316D1B57CD11E8ankaraanado lu_--
Re: Re: How to take output from an include, and embed it intoa variable?
am 23.09.2009 16:36:18 von List Manager
Mert Oztekin wrote:
> Output buffering will do it.
>
> Also I am not sure but did you try retrieving content with fopen() ?
>
> Something like
>
> $file = 'invoicetable_bottom.php';
> fopen("http://yoursite.com/folder/$file","r");
>
> http://tr.php.net/function.fopen
>
> worth trying. Easier than output buffering
>
This would not work. fopen would open the file for read. What you would be
reading is the actual source of the document. Not the data the script would
output when ran.
The ob_* functions are the only way that I know of to do what you are asking
> -----Original Message-----
> From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
> Sent: Wednesday, September 23, 2009 1:36 PM
> To: php-general@lists.php.net
> Subject: [PHP] Re: How to take output from an include, and embed it into a variable?
>
> Hi,
>
> The simplest way (actually the single way I know :) ) would be to
> capture the output using output buffering functions, something like this:
>
> // start output buffering
> ob_start();
>
> // include the file that generates the HTML (or whatever content)
> include "....";
>
> // get output buffer content
> $output=ob_get_contents();
>
> // clean output buffer and stop buffering
> ob_end_clean();
>
> // the content generated in the included file is now in $output variable
> // use it as you consider fit
> .........
>
>
> Regards,
> Puiu
>
>
> Rob Gould wrote:
>> I have an invoice table that is drawn on a number of pages, so I have
>> all the logic in an include-file like this:
>>
>> include "invoicetable_bottom.php";
>>
>>
>> However, now I'm needing to take the output from that include file and
>> pass it as an email. To do that, I need to somehow take the output from
>> this include file and get it into a variable somehow. Is there a simple
>> way to do this?
>>
>> Something like: $emailtcontent = include "invoicetable_bottom.php"?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: How to take output from an include, and embed itinto a variable?
am 23.09.2009 16:58:56 von Ashley Sheridan
On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:
> Mert Oztekin wrote:
> > Output buffering will do it.
> >
> > Also I am not sure but did you try retrieving content with fopen() ?
> >
> > Something like
> >
> > $file = 'invoicetable_bottom.php';
> > fopen("http://yoursite.com/folder/$file","r");
> >
> > http://tr.php.net/function.fopen
> >
> > worth trying. Easier than output buffering
> >
>
> This would not work. fopen would open the file for read. What you would be
> reading is the actual source of the document. Not the data the script would
> output when ran.
>
> The ob_* functions are the only way that I know of to do what you are asking
>
> > -----Original Message-----
> > From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
> > Sent: Wednesday, September 23, 2009 1:36 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] Re: How to take output from an include, and embed it into a variable?
> >
> > Hi,
> >
> > The simplest way (actually the single way I know :) ) would be to
> > capture the output using output buffering functions, something like this:
> >
> > // start output buffering
> > ob_start();
> >
> > // include the file that generates the HTML (or whatever content)
> > include "....";
> >
> > // get output buffer content
> > $output=ob_get_contents();
> >
> > // clean output buffer and stop buffering
> > ob_end_clean();
> >
> > // the content generated in the included file is now in $output variable
> > // use it as you consider fit
> > .........
> >
> >
> > Regards,
> > Puiu
> >
> >
> > Rob Gould wrote:
> >> I have an invoice table that is drawn on a number of pages, so I have
> >> all the logic in an include-file like this:
> >>
> >> include "invoicetable_bottom.php";
> >>
> >>
> >> However, now I'm needing to take the output from that include file and
> >> pass it as an email. To do that, I need to somehow take the output from
> >> this include file and get it into a variable somehow. Is there a simple
> >> way to do this?
> >>
> >> Something like: $emailtcontent = include "invoicetable_bottom.php"?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
That's just crazy talk. If you use fopen on a web URL, then it will
always return the output the script generates. That's how http works!
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: How to take output from an include, and embed it into a
am 23.09.2009 18:13:49 von Ben Dunlap
> $file = 'invoicetable_bottom.php';
> fopen("http://yoursite.com/folder/$file","r");
>
> http://tr.php.net/function.fopen
>
> worth trying. Easier than output buffering
Easier in what sense? It would end up requiring more code than
output-buffering because you'd have to read from the file after
calling fopen(), check for end-of-file, etc., and it seems needlessly
inefficient because it:
- uses a function, fopen(), instead of a language construct, include()
- generates a superfluous HTTP request
I think it's also counter-intuitive. I ran across a similar technique
in some code I was reviewing and I had to really scratch my head and
wonder why the original author of the code did that, instead of just
getting at the file via the local file system.
Finally, it would require the OP to store an include()-ed file inside
of DocumentRoot -- which I personally prefer not to do when I can
avoid it (although that approach is debatable).
Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: How to take output from an include, and embed it intoa variable?
am 23.09.2009 19:03:38 von List Manager
Ashley Sheridan wrote:
> On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:
>> Mert Oztekin wrote:
>>> Output buffering will do it.
>>>
>>> Also I am not sure but did you try retrieving content with fopen() ?
>>>
>>> Something like
>>>
>>> $file = 'invoicetable_bottom.php';
>>> fopen("http://yoursite.com/folder/$file","r");
>>>
>>> http://tr.php.net/function.fopen
>>>
>>> worth trying. Easier than output buffering
>>>
>> This would not work. fopen would open the file for read. What you would be
>> reading is the actual source of the document. Not the data the script would
>> output when ran.
>>
>> The ob_* functions are the only way that I know of to do what you are asking
>>
>>> -----Original Message-----
>>> From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
>>> Sent: Wednesday, September 23, 2009 1:36 PM
>>> To: php-general@lists.php.net
>>> Subject: [PHP] Re: How to take output from an include, and embed it into a variable?
>>>
>>> Hi,
>>>
>>> The simplest way (actually the single way I know :) ) would be to
>>> capture the output using output buffering functions, something like this:
>>>
>>> // start output buffering
>>> ob_start();
>>>
>>> // include the file that generates the HTML (or whatever content)
>>> include "....";
>>>
>>> // get output buffer content
>>> $output=ob_get_contents();
>>>
>>> // clean output buffer and stop buffering
>>> ob_end_clean();
>>>
>>> // the content generated in the included file is now in $output variable
>>> // use it as you consider fit
>>> .........
>>>
>>>
>>> Regards,
>>> Puiu
>>>
>>>
>>> Rob Gould wrote:
>>>> I have an invoice table that is drawn on a number of pages, so I have
>>>> all the logic in an include-file like this:
>>>>
>>>> include "invoicetable_bottom.php";
>>>>
>>>>
>>>> However, now I'm needing to take the output from that include file and
>>>> pass it as an email. To do that, I need to somehow take the output from
>>>> this include file and get it into a variable somehow. Is there a simple
>>>> way to do this?
>>>>
>>>> Something like: $emailtcontent = include "invoicetable_bottom.php"?
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> That's just crazy talk. If you use fopen on a web URL, then it will
> always return the output the script generates. That's how http works!
>
Sorry, my bad. Ash is correct, the method that is suggested will work. But you
will need to enable options in your php.ini that are not on by default for
security reasons, plus as Ben points out, you will need to filter out the scruff
that is generated to capture just the data output from your include.
Mind you that all of this also requires that the file that you are including is
accessible via the web. It could be in a folder that is not web accessible.
Sorry for the initial confusion!
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Re: How to take output from an include, and embed itinto a variable?
am 25.09.2009 04:09:42 von Carl Furst
Jim Lucas wrote:
> Ashley Sheridan wrote:
>
>> On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:
>>
>>> Mert Oztekin wrote:
>>>
>>>> Output buffering will do it.
>>>>
>>>> Also I am not sure but did you try retrieving content with fopen() ?
>>>>
>>>> Something like
>>>>
>>>> $file = 'invoicetable_bottom.php';
>>>> fopen("http://yoursite.com/folder/$file","r");
>>>>
>>>> http://tr.php.net/function.fopen
>>>>
>>>> worth trying. Easier than output buffering
>>>>
>>>>
>>> This would not work. fopen would open the file for read. What you would be
>>> reading is the actual source of the document. Not the data the script would
>>> output when ran.
>>>
>>> The ob_* functions are the only way that I know of to do what you are asking
>>>
>>>
>>>> -----Original Message-----
>>>> From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
>>>> Sent: Wednesday, September 23, 2009 1:36 PM
>>>> To: php-general@lists.php.net
>>>> Subject: [PHP] Re: How to take output from an include, and embed it into a variable?
>>>>
>>>> Hi,
>>>>
>>>> The simplest way (actually the single way I know :) ) would be to
>>>> capture the output using output buffering functions, something like this:
>>>>
>>>> // start output buffering
>>>> ob_start();
>>>>
>>>> // include the file that generates the HTML (or whatever content)
>>>> include "....";
>>>>
>>>> // get output buffer content
>>>> $output=ob_get_contents();
>>>>
>>>> // clean output buffer and stop buffering
>>>> ob_end_clean();
>>>>
>>>> // the content generated in the included file is now in $output variable
>>>> // use it as you consider fit
>>>> .........
>>>>
>>>>
>>>> Regards,
>>>> Puiu
>>>>
>>>>
>>>> Rob Gould wrote:
>>>>
>>>>> I have an invoice table that is drawn on a number of pages, so I have
>>>>> all the logic in an include-file like this:
>>>>>
>>>>> include "invoicetable_bottom.php";
>>>>>
>>>>>
>>>>> However, now I'm needing to take the output from that include file and
>>>>> pass it as an email. To do that, I need to somehow take the output from
>>>>> this include file and get it into a variable somehow. Is there a simple
>>>>> way to do this?
>>>>>
>>>>> Something like: $emailtcontent = include "invoicetable_bottom.php"?
>>>>>
>>>> --
>>>> PHP General Mailing List (http://www.php.net/)
>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>
>>>
>> That's just crazy talk. If you use fopen on a web URL, then it will
>> always return the output the script generates. That's how http works!
>>
>>
>
> Sorry, my bad. Ash is correct, the method that is suggested will work. But you
> will need to enable options in your php.ini that are not on by default for
> security reasons, plus as Ben points out, you will need to filter out the scruff
> that is generated to capture just the data output from your include.
>
> Mind you that all of this also requires that the file that you are including is
> accessible via the web. It could be in a folder that is not web accessible.
>
> Sorry for the initial confusion!
>
>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>>
>
>
>
Do you have php configured to compile files? Why not just backtick the
php -f command??
$cmd = *escapeshellcmd*("/full/path/to/php -f $file");
$email_output = `$cmd`;
# do something with $email_output
?>
Seems easier than a whole http call.. can be risky if the $file variable
can be set by user input (big no no), but other than that.. seeems the
simplest.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Re: How to take output from an include, and embed it
am 25.09.2009 21:12:10 von Geert Tapperwijn
--0016362570ec9870e404746bb99e
Content-Type: text/plain; charset=ISO-8859-1
Can't you just use the eval function, and parse
the code from the include file in it?
... or is there something I'm missing here?
2009/9/25 Carl Furst
>
>
> Jim Lucas wrote:
>
>> Ashley Sheridan wrote:
>>
>>
>>> On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:
>>>
>>>
>>>> Mert Oztekin wrote:
>>>>
>>>>
>>>>> Output buffering will do it.
>>>>>
>>>>> Also I am not sure but did you try retrieving content with fopen() ?
>>>>>
>>>>> Something like
>>>>>
>>>>> $file = 'invoicetable_bottom.php';
>>>>> fopen("http://yoursite.com/folder/$file","r");
>>>>>
>>>>> http://tr.php.net/function.fopen
>>>>>
>>>>> worth trying. Easier than output buffering
>>>>>
>>>>>
>>>>>
>>>> This would not work. fopen would open the file for read. What you
>>>> would be
>>>> reading is the actual source of the document. Not the data the script
>>>> would
>>>> output when ran.
>>>>
>>>> The ob_* functions are the only way that I know of to do what you are
>>>> asking
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
>>>>> Sent: Wednesday, September 23, 2009 1:36 PM
>>>>> To: php-general@lists.php.net
>>>>> Subject: [PHP] Re: How to take output from an include, and embed it
>>>>> into a variable?
>>>>>
>>>>> Hi,
>>>>>
>>>>> The simplest way (actually the single way I know :) ) would be to
>>>>> capture the output using output buffering functions, something like
>>>>> this:
>>>>>
>>>>> // start output buffering
>>>>> ob_start();
>>>>>
>>>>> // include the file that generates the HTML (or whatever content)
>>>>> include "....";
>>>>>
>>>>> // get output buffer content
>>>>> $output=ob_get_contents();
>>>>>
>>>>> // clean output buffer and stop buffering
>>>>> ob_end_clean();
>>>>>
>>>>> // the content generated in the included file is now in $output
>>>>> variable
>>>>> // use it as you consider fit
>>>>> .........
>>>>>
>>>>>
>>>>> Regards,
>>>>> Puiu
>>>>>
>>>>>
>>>>> Rob Gould wrote:
>>>>>
>>>>>
>>>>>> I have an invoice table that is drawn on a number of pages, so I have
>>>>>> all the logic in an include-file like this:
>>>>>>
>>>>>> include "invoicetable_bottom.php";
>>>>>>
>>>>>>
>>>>>> However, now I'm needing to take the output from that include file and
>>>>>> pass it as an email. To do that, I need to somehow take the output
>>>>>> from
>>>>>> this include file and get it into a variable somehow. Is there a
>>>>>> simple
>>>>>> way to do this?
>>>>>>
>>>>>> Something like: $emailtcontent = include "invoicetable_bottom.php"?
>>>>>>
>>>>>>
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>
>>>>>
>>>>
>>>>
>>> That's just crazy talk. If you use fopen on a web URL, then it will
>>> always return the output the script generates. That's how http works!
>>>
>>>
>>>
>>
>> Sorry, my bad. Ash is correct, the method that is suggested will work.
>> But you
>> will need to enable options in your php.ini that are not on by default for
>> security reasons, plus as Ben points out, you will need to filter out the
>> scruff
>> that is generated to capture just the data output from your include.
>>
>> Mind you that all of this also requires that the file that you are
>> including is
>> accessible via the web. It could be in a folder that is not web
>> accessible.
>>
>> Sorry for the initial confusion!
>>
>>
>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
> Do you have php configured to compile files? Why not just backtick the php
> -f command??
>
>
>
> $cmd = *escapeshellcmd*("/full/path/to/php -f $file");
> $email_output = `$cmd`;
>
> # do something with $email_output
>
> ?>
>
> Seems easier than a whole http call.. can be risky if the $file variable
> can be set by user input (big no no), but other than that.. seeems the
> simplest.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--0016362570ec9870e404746bb99e--
Re: Re: How to take output from an include, and embed it into a variable?
am 26.09.2009 01:21:54 von Phpster
On Sep 25, 2009, at 3:12 PM, Geert Tapperwijn
wrote:
> Can't you just use the eval function, and
> parse
> the code from the include file in it?
>
> .. or is there something I'm missing her
Because eval has risks if code gets injected into the code you mean to
run.
Bastien
Sent from my iPod
>
> 2009/9/25 Carl Furst
>
>>
>>
>> Jim Lucas wrote:
>>
>>> Ashley Sheridan wrote:
>>>
>>>
>>>> On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:
>>>>
>>>>
>>>>> Mert Oztekin wrote:
>>>>>
>>>>>
>>>>>> Output buffering will do it.
>>>>>>
>>>>>> Also I am not sure but did you try retrieving content with fopen
>>>>>> () ?
>>>>>>
>>>>>> Something like
>>>>>>
>>>>>> $file = 'invoicetable_bottom.php';
>>>>>> fopen("http://yoursite.com/folder/$file","r");
>>>>>>
>>>>>> http://tr.php.net/function.fopen
>>>>>>
>>>>>> worth trying. Easier than output buffering
>>>>>>
>>>>>>
>>>>>>
>>>>> This would not work. fopen would open the file for read. What
>>>>> you
>>>>> would be
>>>>> reading is the actual source of the document. Not the data the
>>>>> script
>>>>> would
>>>>> output when ran.
>>>>>
>>>>> The ob_* functions are the only way that I know of to do what
>>>>> you are
>>>>> asking
>>>>>
>>>>>
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Puiu Hrenciuc [mailto:hpuiu@xentra.ro]
>>>>>> Sent: Wednesday, September 23, 2009 1:36 PM
>>>>>> To: php-general@lists.php.net
>>>>>> Subject: [PHP] Re: How to take output from an include, and
>>>>>> embed it
>>>>>> into a variable?
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> The simplest way (actually the single way I know :) ) would be to
>>>>>> capture the output using output buffering functions, something
>>>>>> like
>>>>>> this:
>>>>>>
>>>>>> // start output buffering
>>>>>> ob_start();
>>>>>>
>>>>>> // include the file that generates the HTML (or whatever content)
>>>>>> include "....";
>>>>>>
>>>>>> // get output buffer content
>>>>>> $output=ob_get_contents();
>>>>>>
>>>>>> // clean output buffer and stop buffering
>>>>>> ob_end_clean();
>>>>>>
>>>>>> // the content generated in the included file is now in $output
>>>>>> variable
>>>>>> // use it as you consider fit
>>>>>> .........
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Puiu
>>>>>>
>>>>>>
>>>>>> Rob Gould wrote:
>>>>>>
>>>>>>
>>>>>>> I have an invoice table that is drawn on a number of pages, so
>>>>>>> I have
>>>>>>> all the logic in an include-file like this:
>>>>>>>
>>>>>>> include "invoicetable_bottom.php";
>>>>>>>
>>>>>>>
>>>>>>> However, now I'm needing to take the output from that include
>>>>>>> file and
>>>>>>> pass it as an email. To do that, I need to somehow take the
>>>>>>> output
>>>>>>> from
>>>>>>> this include file and get it into a variable somehow. Is
>>>>>>> there a
>>>>>>> simple
>>>>>>> way to do this?
>>>>>>>
>>>>>>> Something like: $emailtcontent = include
>>>>>>> "invoicetable_bottom.php"?
>>>>>>>
>>>>>>>
>>>>>> --
>>>>>> PHP General Mailing List (http://www.php.net/)
>>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>> That's just crazy talk. If you use fopen on a web URL, then it will
>>>> always return the output the script generates. That's how http
>>>> works!
>>>>
>>>>
>>>>
>>>
>>> Sorry, my bad. Ash is correct, the method that is suggested will
>>> work.
>>> But you
>>> will need to enable options in your php.ini that are not on by
>>> default for
>>> security reasons, plus as Ben points out, you will need to filter
>>> out the
>>> scruff
>>> that is generated to capture just the data output from your include.
>>>
>>> Mind you that all of this also requires that the file that you are
>>> including is
>>> accessible via the web. It could be in a folder that is not web
>>> accessible.
>>>
>>> Sorry for the initial confusion!
>>>
>>>
>>>
>>>> Thanks,
>>>> Ash
>>>> http://www.ashleysheridan.co.uk
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>> Do you have php configured to compile files? Why not just backtick
>> the php
>> -f command??
>>
>>
>>
>> $cmd = *escapeshellcmd*("/full/path/to/php -f $file");
>> $email_output = `$cmd`;
>>
>> # do something with $email_output
>>
>> ?>
>>
>> Seems easier than a whole http call.. can be risky if the $file
>> variable
>> can be set by user input (big no no), but other than that.. seeems
>> the
>> simplest.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php