                                                                                       <?php
//-->-->-->-->-->-->-->-->
//-- Description:
//--   The purpose of this function is to fill an HTML template with
//--   content which can then be streamed to the user as a useful and
//--   valid web-page. 
//--
//--   This function, like all dodgy template languages, relies on
//--   certain special 'tags' being present in the HTML, which are
//--   in fact just strings within HTML comment delimiters. This is
//--   analogous to the Zope DTML system although obviously not 
//--   as complex.
//--
//-- Author: 
//--   matth3wbishop@yahoo.com
//--   http://www.geocities.com/matth3wbishop/


function fnFillWebTemplate(
  $sTemplateContents,
  $sPageContent,
  $sPageTitle = '',
  $sMetaDescription = '')
{

  if ($sMetaDescription == "")
  {
    $sMetaDescription = $sPageTitle;
  }

  $sReturn = $sTemplateContents;

  //-- Put a meaningful title into the HTML
  $sReturn = preg_replace(
     "#<title>.*</title>#im", "<title>$sPageTitle</title>", $sReturn);

  
  $sReturn = preg_replace(
     "#<!--meta-description-->#im", "$sMetaDescription", $sReturn);

  //-- Insert the page contents at the spot specified by the template
  if (stristr($sReturn, '<!--page-content-->'))
  {
    //-- This is an older format, which I would discourage from use
    $sReturn = preg_replace(
       "#<!--page-content-->#im", "$sPageContent", $sReturn);
  }
  elseif (stristr($sPageContent, "<!--@page-content-->"))
  {
    $sReturn = preg_replace(
       "#<!--@page-content-->#im", "$sPageContent", $sReturn);
  }
  //  $sReturn = preg_replace(
    //   "#<!--page-content-->#im", "$sPageContent", $sReturn);

  return $sReturn;
} //-- function fnFillWebTemplate 
     

//--<--<--<--<--<--<--<--<
?>
                                                                                                                                            