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.

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 :)

nice add-on

@TKO You could have added to code snippets.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.