SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating Static html pages from dynamic php content???

    Here's my problem:
    I am trying to create a new shopping cart system that will create static .html pages from my php generated pages. So that I don't have to query the database everytime information is requested. Such as a Product information sheet.

    Here is the current code I've been working with, but when I view the new generated file, the php code is still there. Not the generated HTML.
    Code:
    <?php
        ob_start(); // start trapping output
    $myFile = "templates/temp1.php";
    $staticpage = file_get_contents($myFile);
    
    echo $staticpage;
    
    
        $output = ob_get_contents(); // get contents of output
        //write to file, e.g.
        $newfile="default.html"; 
        $file = fopen ($newfile, "w"); 
        fwrite($file, $output); 
        fclose ($file);  
        ob_end_clean(); // discard output
    ?>
    Could someone please help with this?
    You know you cooler than me...

  2. #2
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of the above, why don't you use some reliable PHP caching system? Caching systems are exactly for purposes like the one you're describing. Two obvious choices:

    http://sk.php.net/apc/
    http://framework.zend.com/manual/en/zend.cache.html

  3. #3
    SitePoint Zealot stuffedbuggy's Avatar
    Join Date
    Sep 2008
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I seem to of found this which only displays the html output without including the php in the page.

    Code:
    <?php
    $cacheFile = file_get_contents('https://fieldsimc.com/optimization/processkeys.php?link=&keywordsearch=');
    
    
        ob_start();
        // write content
        echo $cacheFile;
        $content = ob_get_contents();
        ob_end_clean();
        file_put_contents("ztest.php",$content);
        echo $content;
    
    ?>
    You know you cooler than me...


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
  •