Professional Web Applications Themes

HTML file generation from PHP scripts - PHP Development

Thanks for the suggestion guys, but I did forget an important detail. I do not have access to a unix shell so the whole thing must be self-contained in the php script. I could substitute my current 'echo' statements with some kind of fprintf function, so that the output is redirected to a file, but I was trying to find out if there was an easier way. Let me know. Ciao ciao! Manu...

  1. #1

    Default Re: HTML file generation from PHP scripts

    Thanks for the suggestion guys,
    but I did forget an important detail.

    I do not have access to a unix shell
    so the whole thing must be self-contained
    in the php script.

    I could substitute my current 'echo'
    statements with some kind of fprintf
    function, so that the output is redirected
    to a file, but I was trying to find out if
    there was an easier way.

    Let me know.

    Ciao ciao!

    Manu
    Emanuele D'Arrigo Guest

  2. #2

    Default Re: HTML file generation from PHP scripts

    Emanuele D'Arrigo wrote:
    > Thanks for the suggestion guys,
    > but I did forget an important detail.
    >
    > I do not have access to a unix shell
    > so the whole thing must be self-contained
    > in the php script.
    >
    > I could substitute my current 'echo'
    > statements with some kind of fprintf
    > function, so that the output is redirected
    > to a file, but I was trying to find out if
    > there was an easier way.
    >
    > Let me know.
    >
    > Ciao ciao!
    >
    > Manu
    Are you able to write files in your webspace through PHP? (IE create if
    non-exist, or overwrite if it does.)

    If so, then "Default User" just gave you the method. If not, then your
    best bet is to either switch hosts, or set up a development site on your
    computer. THen when you have done updates to the content, use something
    like wget to grab a static copy to upload.

    --
    Justin Koivisto - [email]spamkoivi.com[/email]
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Justin Koivisto Guest

  3. #3

    Default Re: HTML file generation from PHP scripts



    Emanuele D'Arrigo wrote:
    >
    > Thanks for the suggestion guys,
    > but I did forget an important detail.
    >
    > I do not have access to a unix shell
    > so the whole thing must be self-contained
    > in the php script.
    What do you mean? There's no need to have shell access as long as you
    can read and write to files on the host. Please explain your situation
    fully.
    > I could substitute my current 'echo'
    > statements with some kind of fprintf
    > function, so that the output is redirected
    > to a file, but I was trying to find out if
    > there was an easier way.
    Easier way? What exactly are you looking for? There's no magic, if you
    want something saved from a prior execution you have to put somewhere.
    For a situation like web pages, files are the natural way. Dump your
    output to a file, serve it up if it's within the time window, recreate
    it when it's not.

    BTW, there's no fprintf() function, you'd be looking for fwrite() or
    fputs(). Unless your code that constructs the output now is horribly
    complicated, you should be able to rework it in less time than it takes
    to agonize over it. You'd already be done.


    Brian Rodenborn
    Default User Guest

  4. #4

    Default Re: HTML file generation from PHP scripts

    On Thu, 26 Jun 2003 11:41:39 +0100, David Mackenzie
    <dcmtarbrax.freeserve.co.uk> wrote:
    >>So I was wondering: having a functional script,
    >>is there a way to re-direct its output to an html
    >>file? Ideally, if the file is there already and
    >>is less than 24 hrs old, the script should actually
    >>redirect the browser to that file. Otherwise,
    >>the script should generate one and then redirect
    >>the browser to that file anyway.
    >
    >I understand that Apache's mod_rewrite can rewrite URLs based on date
    >and time, but that is beyond my skill level.
    Have a look at this page in the Apache manual; not based on date and time, but
    it seems close to the OP's request:

    [url]http://httpd.apache.org/docs-2.0/misc/rewriteguide.html#ToC2[/url]

    Search for 'On-the-fly Content-Regeneration' about 2/3rds down the page.

    --
    Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  5. #5

    Default Re: HTML file generation from PHP scripts



    Emanuele D'Arrigo wrote:
    > I can uploaded and download files to my account, via ftp,
    > and of course I can run the scripts when I call them up
    > trough the browser. But I do not have a telnet or ssh
    > access to the server, which I believe it means I can only
    > execute things inside a script.
    That's common, and should present no problems.

    > Basically I'm looking for the php equivalent of
    > the unix syntax: myScript.php > myFile.html
    > where the output of the php script is redirected
    > to a file. Is it possible to dump the result of
    > a php script -executed- by another php script?
    That doesn't really fit your original problem description. What is wrong
    with opening the file and writing to it using the PHP file methods?
    > A startup script would be the one that check for
    > the existance and age of the html file, and
    > if necessary it would start the actual script and
    > dump its output into the file overwriting it.
    Why? Include that functionality in your formhandler the way I showed you
    before.

    > I see what you mean and thanks for the tip about fwrite and fputs.
    > As I'm quite new to php I am not just trying to find a way to do it.
    > Indeed I could probably easily substitute all my echo statement with
    > an fwrite and get away with it, but I was wondering if there's an
    > easier way that keep the current script the way it is, and runs it
    > as described few paragraph earlier.

    The easy way is to do it right. Then you'll have a correct, flexible way
    of doing, so when the inevitable changes come up in the future you'll be
    set.

    I showed the basic framework, add another routine to open the output
    file for writing, and change your echo statements to fputs. Just do it.
    Like I said, you'd already be done if you just sat down and cranked on
    it for a hour or so.

    A decent text editor can help a lot in search and replace.



    Brian Rodenborn
    Default User Guest

  6. #6

    Default Re: HTML file generation from PHP scripts

    [email]manu3dmclink.it[/email] (Emanuele D'Arrigo) wrote in message news:<42485035.0306260053.5ed192f0posting.google. com>...
    > So I was wondering: having a functional script,
    > is there a way to re-direct its output to an html
    > file? Ideally, if the file is there already and
    > is less than 24 hrs old, the script should actually
    > redirect the browser to that file. Otherwise,
    > the script should generate one and then redirect
    > the browser to that file anyway.
    >
    > Hints? Suggestions? Am I asking too much?
    Thinking out loud here so feel free to shoot the ideas down but if
    you've got a fuctional script then wrapping a little bit of ob_start
    and ob_end could be a way around it.

    It means that you could test for the file, if it exists and recent
    enough, dump that to the browser via readfile (I think that's the
    function that opens and dumps contents to the browser). If it needs
    re-creating then use ob_start to redirect output, save the contents as
    a file and display it.

    I've never done it but these functions exist and this would be my
    initial way of tackling the problem without rewriting the code. You
    may want to search around for "cache" and "cacheing" as this is what
    you're effectively setting up.

    HTH
    Paul Liversidge Guest

  7. #7

    Default Re: HTML file generation from PHP scripts

    Paul, that sounds like exactly what I was looking for.

    Thank you!

    Manu
    Emanuele D'Arrigo Guest

Similar Threads

  1. Writing HTML with PHP, executing external scripts
    By Dariusz in forum PHP Development
    Replies: 0
    Last Post: December 4th, 08:15 PM
  2. HTML Generation (Next Generation CGI)
    By John W. Long in forum Ruby
    Replies: 4
    Last Post: November 24th, 04:24 AM
  3. HTML generation
    By Philip Mak in forum Ruby
    Replies: 14
    Last Post: September 17th, 05:43 PM
  4. Replies: 2
    Last Post: September 3rd, 09:16 PM
  5. executing perl scripts from php/html
    By Gary Petersen in forum PHP Development
    Replies: 0
    Last Post: August 31st, 10:19 AM

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