Professional Web Applications Themes

storing included file output in buffer? - PHP Development

I have a class webpage that allows me to build a page before outputting it. It has member functions header(), footer(), body('literal html string'), bodyhtmlfile ('filename to html file') I would like to be able to include (the output) of php files as well. Is it possible to have a separate php file produce some output (e.g. some table filled with mysql db entries) which I can store in a webpage instance ? I tried this: class webpage { [...] function bodyphpfile ($filename) { $this->content .= include "$filename"; } [...] } but as I expected include doesn't do it, as ...

  1. #1

    Default storing included file output in buffer?

    I have a class webpage that allows me to build a page before outputting it.

    It has member functions header(), footer(), body('literal html string'),
    bodyhtmlfile ('filename to html file')

    I would like to be able to include (the output) of php files as well.
    Is it possible to have a separate php file produce some output (e.g.
    some table filled with mysql db entries) which I can store in a webpage
    instance ?

    I tried this:
    class webpage
    {
    [...]
    function bodyphpfile ($filename)
    {
    $this->content .= include "$filename";
    }
    [...]
    }

    but as I expected include doesn't do it, as it only returns a bool.
    If I treat the php file like a html file (pd line by line) it simply
    adds the php lines to the output, but of course it isn't pd by the
    PHP interpreter.


    Help appreciated.
    KR
    Schraalhans
    Schraalhans Guest

  2. #2

    Default Re: storing included file output in buffer?

    Schraalhans Keukenmeester wrote:

    <snip> 

    You could use output buffering, but a simpler solution would be:

    $this->content .= file($filename);

    (assuming that filename is a URL, and there is no restriction on the file
    wrappers).

    You might have to mung the output to get embeddable html.

    HTH

    C.
    Colin Guest

  3. #3

    Default Re: storing included file output in buffer?

    Colin McKinnon wrote: 
    > You could use output buffering, but a simpler solution would be:
    >
    > $this->content .= file($filename);
    >
    > (assuming that filename is a URL, and there is no restriction on the file
    > wrappers).
    >
    > You might have to mung the output to get embeddable html.[/ref]

    That would not work I think as it does not p the PHP file, merely
    copies the file verbatim. While that works fine for html, I need the php
    code to be executed instead.
    Schraalhans Guest

  4. #4

    Default Re: storing included file output in buffer?

    >> [...] 
    >
    > That would not work I think as it does not p the PHP file, merely
    > copies the file verbatim. While that works fine for html, I need the php
    > code to be executed instead.[/ref]

    Read again: "assuming that filename is a URL". If you give local path
    to "file" function, then it does not p the file, but if you give it
    an URL, then the file is retrieved using HTTP, which means that web server
    is going to p it (if it is PHP file).

    I think it's not a good way to do it (use output buffering as Colin also
    suggested) cause you have to give web access to the file you are trying
    to include.


    Hilarion
    Hilarion Guest

  5. #5

    Default Re: storing included file output in buffer?

    Hilarion wrote: 
    >>
    >>
    >> That would not work I think as it does not p the PHP file, merely
    >> copies the file verbatim. While that works fine for html, I need the
    >> php code to be executed instead.[/ref]
    >
    >
    > Read again: "assuming that filename is a URL". If you give local path
    > to "file" function, then it does not p the file, but if you give it
    > an URL, then the file is retrieved using HTTP, which means that web server
    > is going to p it (if it is PHP file).
    >
    > I think it's not a good way to do it (use output buffering as Colin also
    > suggested) cause you have to give web access to the file you are trying
    > to include.
    >
    >
    > Hilarion[/ref]
    Thanks, I missed that essential bit. Smart. I also see the downside like
    you said. Any other suggestions ? Forget about it altogether and keep
    all the php stuff in functions in include files and include them all in
    the main php file ?
    Schraalhans Guest

  6. #6

    Default Re: storing included file output in buffer?

    > Thanks, I missed that essential bit. Smart. I also see the downside like 

    Are you doing this for templating purposes? Perhaps Smarty is the answer?
    http://smarty.php.net

    Michael


    Michael Guest

Similar Threads

  1. Z/Depth buffer output
    By l0die in forum Macromedia Director 3D
    Replies: 2
    Last Post: March 20th, 06:37 PM
  2. storing the passthru() output as an array
    By Michael in forum PHP Development
    Replies: 3
    Last Post: October 7th, 02:18 AM
  3. Replies: 0
    Last Post: October 2nd, 03:19 AM
  4. #25701 [Bgs]: Calling flush from within an output buffer prevents headers from being sent
    By scottmacvicar at ntlworld dot com in forum PHP Development
    Replies: 0
    Last Post: September 30th, 11:24 PM
  5. [PHP] PHP output|Buffer, PLEASE ADVISE
    By Rasmus Lerdorf in forum PHP Development
    Replies: 1
    Last Post: September 21st, 02:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139