I need to create html files from php files using php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    I need to create html files from php files using php

    I am very new to PHP, although I have been using ASP for a few years.

    I use a product in ASP called ASPTear, it's a small dll that my
    hosting company happens to have loaded.

    Basically you can set up a function that you can pass an ASP page to
    and it will read the ASP and write out an HTML file.

    I use this to save load on the server and speed up my site, I have a
    few include files that look up data and then present it, this data
    does not change very often, so I run a routine called rebuildhtml.asp
    that will call a few ASP files and create HTML versions.

    I am now converting the site to PHP as I want to use mod_rewrite, what
    I need is a routine that I can pass a php file to and end up with an
    HTML version.

    For example

    rewrite(somefil e.php)

    Will create somefile.html

    I am sure this can't be too difficult, but as a newbie I cannot find
    out how to do it.

    Any help appriciated.

    Dennis
  • Pedro Graca

    #2
    Re: I need to create html files from php files using php

    Dennis wrote:[color=blue]
    > what
    > I need is a routine that I can pass a php file to and end up with an
    > HTML version.
    >
    > For example
    >
    > rewrite(somefil e.php)[/color]





    Happy Coding :-)
    --
    USENET would be a better place if everybody read: | to mail me: simply |
    http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
    http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
    http://www.expita.com/nomime.html | and *NO* attachments. |

    Comment

    • Anonymous

      #3
      Re: I need to create html files from php files using php

      Dennis wrote:
      [color=blue]
      > I am now converting the site to PHP as I want to use mod_rewrite, what
      > I need is a routine that I can pass a php file to and end up with an
      > HTML version.[/color]

      I don't know a routine but a program that does what you want. It's
      called php.exe. ;-)

      php.exe -q filename.php > filename.html

      This command will create the HTML page which the script would create
      when it is run on a server. But that would make the page static.

      The whole point of server side scripting is to have dynamic pages that
      can change with user input, database content, etc., so I don't think
      making your pages static is a really good idea. Except if the server is
      heavily accessed and the content of your pages don't change too often.
      Then making everything static might make sense to reduce server load.

      Bye!

      Comment

      • Dennis

        #4
        Re: I need to create html files from php files using php

        Thanks Pedro,

        That looks promising !

        Dennis

        Pedro Graca <hexkid@hotpop. com> wrote in message news:<slrncnqih h.oe1.hexkid@ID-203069.user.uni-berlin.de>...[color=blue]
        > Dennis wrote:[color=green]
        > > what
        > > I need is a routine that I can pass a php file to and end up with an
        > > HTML version.
        > >
        > > For example
        > >
        > > rewrite(somefil e.php)[/color]
        >
        >
        > http://www.php.net/ob_start
        >
        >
        > Happy Coding :-)[/color]

        Comment

        • Dennis

          #5
          Re: I need to create html files from php files using php

          Thanks for your response.

          It is only a few include files that I want to turn static each time
          their content changes, perhaps a couple of times a week, but each of
          these pages makes database calls, so if I leave them dynamic the
          system will be repeatedly making demands on the database for every
          page on my site as some of these includes are in the header.

          I need to be able to do this from within a php page rather than from
          the command line, so Pedro's solution seems to fit.

          Dennis

          Anonymous <anonymous@nowh ere.invalid> wrote in message news:<417D8A0B. F9ACC726@nowher e.invalid>...[color=blue]
          > Dennis wrote:
          >[color=green]
          > > I am now converting the site to PHP as I want to use mod_rewrite, what
          > > I need is a routine that I can pass a php file to and end up with an
          > > HTML version.[/color]
          >
          > I don't know a routine but a program that does what you want. It's
          > called php.exe. ;-)
          >
          > php.exe -q filename.php > filename.html
          >
          > This command will create the HTML page which the script would create
          > when it is run on a server. But that would make the page static.
          >
          > The whole point of server side scripting is to have dynamic pages that
          > can change with user input, database content, etc., so I don't think
          > making your pages static is a really good idea. Except if the server is
          > heavily accessed and the content of your pages don't change too often.
          > Then making everything static might make sense to reduce server load.
          >
          > Bye![/color]

          Comment

          • Dennis

            #6
            Re: I need to create html files from php files using php

            Thanks for your help:

            I now have the following:

            <?php
            function buildhtml($strp hpfile, $strhtmlfile) {

            echo "Building ".$strhtmlfile. "<br>";

            // start buffering the output
            ob_start();

            include($strphp file);

            // write to a file
            $data = ob_get_contents ();
            $fp = fopen ($strhtmlfile, "w");
            fwrite($fp, $data);
            fclose($fp);
            ob_end_clean();
            }

            // make calls to the buildhtml function here, giving input and output filenames
            buildhtml("inde x.php","index.h tml");
            ?>

            It works great !

            Thanks again

            Dennis

            Comment

            • Pedro Graca

              #7
              Re: I need to create html files from php files using php

              Dennis wrote:
              [snip][color=blue]
              > It works great ![/color]

              Well done, Dennis! :)
              [color=blue]
              > Thanks again[/color]

              You're welcome.
              --
              USENET would be a better place if everybody read: | to mail me: simply |
              http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
              http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
              http://www.expita.com/nomime.html | and *NO* attachments. |

              Comment

              • Anonymous

                #8
                Re: I need to create html files from php files using php

                Dennis wrote:[color=blue]
                >
                > Thanks for your response.
                >
                > It is only a few include files that I want to turn static each time
                > their content changes, perhaps a couple of times a week, but each of
                > these pages makes database calls, so if I leave them dynamic the
                > system will be repeatedly making demands on the database for every
                > page on my site as some of these includes are in the header.[/color]

                That's correct. But you are aware that database changes are not going to
                be reflected on the website until the HTML files are recreated?
                [color=blue]
                > I need to be able to do this from within a php page rather than from
                > the command line, so Pedro's solution seems to fit.[/color]

                You do know that you can execute external programs within a PHP script
                using exec(), don't you? :-)

                But any solution that works is a good solution.

                Bye!

                Comment

                Working...