0

I just spent some time tryin to figure this out and found out how, so thought i would share.
(hope this is the right section for this.)

<?php
ob_start();
include('index.php');
$content = ob_get_clean();
?> 

then insert where ever you want it to show up.

<?php echo $content;?>

Hope this helps someone save some time.

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Tko_1
0

Thanks for sharing.....

and you can also expand the above codes to make a cache file of the index.php above.

Using the same concept, we can make a cache of the index.php above . Create a new directory called cache. make sure this is writtable for the script.

Say, we have a page called entry.php page. add this code in the middle where you want the index.php to appear.

<?php

## you must define how many seconds you want the cache to last..
$cachetime = 10080 * 60; 
$cachefile = "cache/index.html";

if(file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)))  {


   ## the page has been cached from an earlier request

   ## output the contents of the cache file

    include($cachefile); 

    }
    else{
      ## this will create cache html page of the index.php
    ob_start(); 

    include ('index.php');

    $cachefile = "cache/index.html";

  ## open the cache file "cache/index.html" for writing
   $fp = fopen($cachefile, 'w');

  ##save the contents of output buffer to the file

  fwrite($fp, ob_get_contents());
  ## close the file

   fclose($fp);

  ## Send the output to the browser
  ob_end_flush();

?>

That will create a templating system cache like function of the index.php , which is proven to speed up the page load. Ideal if the content does not change a lot..

Coool :)

Edited by veedeoo: added more info.

0

urtrivedi, yes i seen that after i posted. will do in the future.
Thank you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.