I made this so that in my language files I can have included files as values!
here's the functions code:
<?php
include("lang/lang-english.php");
function parseTemplate( $fTemplateFile )
{
global $string;
if( file_exists( $fTemplateFile ) )
{
$fileContents = file_get_contents( $fTemplateFile );
foreach( $string as $tag => $value )
{
if( substr( $tag, 0, 2 ) == "__" )
{
if( file_exists( $value ) )
{
$includedFileContents = file_get_contents( $value );
$fileContents = str_replace( $tag, $includedFileContents, $fileContents );
}
else
{
echo "<b>Error: </b> Specified file(" . $value . ") not found!";
die( );
}
}
else
{
$fileContents = str_replace( $tag, $value, $fileContents );
}
}
return $fileContents;
}
else
{
echo "<b>Error: </b> Template file(" . $fTemplateFile . ") not found!";
die( );
}
}
?>
and here is what my language file looks like:
<?php
$string = array(
"{TITLE}" => "KurtzDownloadDB",
"{VERSION}" => "v. 0.1.1 BETA",
"{COPY}" => "Copyright © 2005 by Shawn Kurtz",
"__{CONTENT}" => "themes/default/_test.html"
);
?>
What it does is replaces all {TAGS} with their values. But, if a tag is prefixed like: __{TAG}, then the value of that tag will be included instead of assigned.