I posted a thread to learn more about xml and parser.
I have been reading the article below.
http://www.devshed.com/c/a/PHP/Building-a-Template-Parser-Class-with-PHP-Part-I/
there are three pages default_template.htm, template.htm, and template.php refreced with in the script. I have typed up the code to walk through it instead to copy and paste.
It seems strange that there are two .htm files yet there is only one htm page.
<!DOCTYPE html PUBLIC "−//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1−transitional.dtd">
<html>
<head>
<title>{title}</title>
<meta http−equiv="Content−Type" content="text/html;
charset=iso−8859−1" />
<link rel="stylesheet" type="text/css" href="style.css"
/>
</head>
<body>
<div id="header">{header}</div>
<div id="navbar">{navbar}</div>
<div id="leftcol">{leftcontent}</div>
<div id="content">{maincontent}</div>
<div id="rightcol">{rightcontent}</div>
<div id="footer">{footer}</div>
</body>
</html>
the two other elements of this templinting system is the
Hereโs the initial definition:
<?php
class templateParser {
// member definition
var $output;
function templateParser(){
// constructor setting up class initialization
}
function parseTemplate(){
// code for parsing template files
}
function display(){
// code for displaying the finished parsed page
}
}
the default_template.htm is mentioned in the function templateParser()
function
templateParser($templateFile='[COLOR=blue]'default_template.htm'[/COLOR] default_template.htm'){
(file_exists($templateFile))?$this−>output=
file_get_contents($templateFile):die('Error:Template
file '_
.$templateFile.' not found');
}
article
Finally, hereโs a possible real implementation for the class:
template.php and template.htm is refrenced in this script ๐ ๐ ๐
<?php
// include the class
require_once('template.php');
// instantiate a new template Parser object
$tp=&new templateParser('template.htm');
// define parameters for the class
$tags=array('title'=>'You are seeing the template
parser class in
action!','header'=>'header.php','navbar'=>
'navigation bar.php','leftcontent'=>'leftcontent.php',
'maincontent'=>'maincontent.php',
'rightcontent'=>'rightcontent.php',
'footer'=>'footer.php');
// parse template file
$tp−>parseTemplate($tags);
// display generated page
echo $tp−>display();
?>
hence I see two php script layers and one html layer. My goal is to learn php and xml marriage.
The problem is I do not know what file name belongs to which one without guessing . I have some assumtion but I am still learning.
Thanks Tom