Re: Re: Re: How to take output from an include, and embed it into a variable?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can't you just use the eval <http://nl2.php.net/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 <cfurst@xxxxxxxxxxxxxxxxxxxx>

>
>
> 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@xxxxxxxxx]
>>>>> Sent: Wednesday, September 23, 2009 1:36 PM
>>>>> To: php-general@xxxxxxxxxxxxx
>>>>> Subject:  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
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux