Ten system to nic specjalnego najprostsze podmienianie, równie dobrze preg_replace mogłeś zastosować albo wykorzystać poprostu file_get_contents, z plikiem który by zawierał
<div><?=$zmienna?></div>
a zmienne być tworzył w php ;]
stworzyłem coś takiego pod obsługę templaków napisanych w xslt:P jak możecie to zajrzyjcie i powiedzcie co jest nie tak, co można poprawić:
class ethtpl:
template.php
<?php
class ethtpl{
public $tpl;
public $_xsl;
public $_vars;
public $translator=0;
public $lang;
public $_langPack;
public function __construct($file=""){
header("Content-type:text/xml"); else $this->_xsl = $file;
}
public function set($name,$var){
$this->_vars[$name] = $var;
}
public function setTranslator($lang){
$this->_translator=1;
$this->lang = $lang;
$this->loadLangPack();
$this->translator=1;
$this->lang = $lang.".xml";
$this->loadLangPack();
}else{
exit("Nie odnalazlem pliku jezykowego"); }
}
public function loadLangPack(){
$this->_langPack
= @simplexml_load_file
($this->lang)or
die("Plik langPack nie jest prawidłowym plikiem xml"); }
public function translate($key,$value){
$translated = trim($this->_langPack
->$key); $translated?$translated = $translated:$translated =$value;
return $translated;
}
public function array2xml($array,$tag=0){
foreach($array as $key=>$value){
$tag?$this->tpl.='<'.$tag.'>':$this->tpl;
$this->array2xml($value,$key);
$tag?$this->tpl.='</'.$tag.'>':$this->tpl;
}
else{
$this->translator?$this->tpl .= '<'.$key.'>'.$this->translate($key,$value).'</'.$key.'>':$this->tpl .= '<'.$key.'>'.$value.'</'.$key.'>';
}
}
}
public function display(){
$this->tpl ='<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="'.$this->_xsl.'"?><tpl>';
$this->array2xml($this->_vars);
$this->tpl.='</tpl>';
}
}
?>
plik index.php
<?php
require_once('template.php');
$tpl = new ethtpl('template.xsl');
1=>array(
'title'=>'Empire Burlesque',
'artist'=>'Bob Dylan',
'country'=>'USA',
'company'=>'Columbia',
'price'=>'10.90',
'year'=>'1985',
),
2=>array(
'title'=>'Empire2 Burlesque2',
'artist'=>'Bob Dylan',
'country'=>'USA',
'company'=>'Columbia',
'price'=>'10.90',
'year'=>'1985',
)
);
$tpl->set('cd',$ar);
$tpl->set('name','adam');
$tpl->setTranslator("pl");
$tpl->display();
?>
plik langPack
pl.xml
<?xml version="1.0" encoding="utf-8"?>
<langPack>
<name>Krzyś</name>
</langPack>
plik xslt
template.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="tpl/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
<xsl:value-of select="tpl/name"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
To tymczasowo taka mini beta, zrobiona w 2h