Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Can I automatically save PHP generated pages as HTM?

  1. #1
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Can I automatically save PHP generated pages as HTM?

    I converted most of the pages on my site to PHP to make updating simpler using includes. Then I discovered that Google and Yahoo had dropped the pages from their indexes because the pages were being generated on the fly.

    Is it possible to have a PHP program which would read in .PHP filenames from a text file, build pages from the PHP code and automatically save the built page on the server as HTM with the same filename with a .HTM extension.

    For example, if the text file has a line /mydir/mypage.php the program should automatically create /mydir/mypage.htm, overwriting an existing file if present.
    Cheers
    Billy

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You want to use mod_rewrite to make the pages look like static HTML. Read http://www.fluidthoughts.com/howto/mod_rewrite/.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey

    Thanks for the reply. I do not think this is an option for a number of reasons.
    1) I am using a hosting service, and I doubt if they will allow me to change any Apache related settings
    2) Even if they did, I would not have a clue how to go about it (I do not understand most of whats in the page you referred me to)
    3) The search engines would probably not index the pages because of the re-direct. Yahoo show how they handle re-directs and, unless I've misinterpreted, when a re-direct is to a page in the same domain they index the referring page rather than the target page
    4) When I converted to PHP, I browsed the site with Lynx and it displayed content as expected. But the engines apparently did not bother to examine the content, just dropped the page (even though they crawl the site daily). If they are clever enought to work out that the page is not actually static, I am left with the same problem.
    5) Even if I re-direct, what am I re-directing from and to?

    I have already converted back to HTM by browsing the PHP page and saving it as .htm manually (this has already got some of the pages back in the Google index), so I would prefer to stick with this method, but obviously doing it manually is time-consuming and tedious.

    Text on one of the links from the page you referred me to says " It is easy to directly pre-generate a page to its static form" but does not say how. This is what I need.
    Cheers
    Billy

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I see. You'll have a slight problem there, in that it'll not be dynamic if you do so, updating itself on time schedule (if you run a cron job or similar) rather than when the user accesses it. However...
    PHP Code:
    <?php
    $files 
    file("filelist.txt");
    for(
    $i 0$i count($files); $i++) {
      
    ob_start();
      include(
    $files[$i]);
      
    $page ob_get_contents();
      
    ob_end_clean();
      if(
    strpos($files[$i], ".php") > -1) {
        
    $file fopen(substr($files[$i], -4) . ".html");
        
    fputs($file$page);
        
    fclose($file);
      }
    }
    ?>
    This will read files from filelist.txt and, if each has a .php extension, generate a static page, the name of which will be the original filename with a .html extension instead of .php. You could, if you wanted, add in code to walk through your directories. By the way, if you don't have dynamic content in your pages (as it would seem, if you can replace them so easily with static pages) you shouldn't name them .php in the first place. PHP parsing static pages slows down the server response time to no particular use.
    Last edited by Twey; 12-02-2005 at 02:24 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks again Twey. That looks exactly like what I need.

    The pages are in two languages and are semi-dynamic in that the data on many of them changes fairly regularly.

    Prior to switching to PHP I had to edit the HTM directly, cutting and pasting the data and then uploading the new page (I didn't want to use scripts to ensure accessibilty). With PHP pages I was able to change data simply by modifying an included text file.

    Also, new pages are added quite often with exactly the same layout as exisitng pages. I was able to automate the creation of new pages using PHP just by copying any existing page with a new filename. The routine includes the correct data and generates meta tags and other variable text based on the filename.

    Finally I wanted every page in each language to have a link to all other pages in that language so I used includes for navigation. This saved me from having to edit all existing pages each time a new one is added.

    Hopefully with the aid of your script, I will be able to retain the advantages of using PHP while still having static pages.

    Thanks again.
    Cheers
    Billy

  6. #6
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey

    Got the script working but I needed to change the fopen slightly so I'm posting the change in case anybody else wants to use it.

    $file = fopen(substr($files[$i], 0,strlen($files[$i])-4) . ".html",'w');

    Once again many thanks.
    Cheers
    Billy

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Whoops, yes. Sorry.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Nov 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post It wont work for mine, can you please look at it.

    Hi,
    I got dynamic website in php. it returns images and contents when hit on some page.

    When i run this script it give me this error,


    Warning: main(index.php ): failed to open stream: No such file or directory in /mnt/w0401/d04/s45/b0225e10/www/test/dynamic.php on line 5

    Warning: main(index.php ): failed to open stream: No such file or directory in /mnt/w0401/d04/s45/b0225e10/www/test/dynamic.php on line 5

    Warning: main(): Failed opening 'index.php ' for inclusion (include_path='.:/usr/local/nf/lib/php') in /mnt/w0401/d04/s45/b0225e10/www/test/dynamic.php on line 5


    It says error on line 5 here " include ($files[$i]);"

    can you please help me how can i run this script working. I want to run is ASAP

    thanks in advance

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You have a trailing space after one of the filenames in your list.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Nov 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    You have a trailing space after one of the filenames in your list.
    Thanks Twey,

    It is realy helpful and I fixed this problem. I was trying to run this script from 3 days and could not find where was error. I never noticed about a space.

    thanks again

    imi


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
  •