Buongiorno, son nuovo del forum. Ho il seguente problema, non sono esperto di programmazione, ma prendendo spunto qua e là riesco a far funzionare il mio sito. Da qualche giorno non mi funziona più il file template che uso insieme a php. Il passaggio da posix a pcre(qiundi mi riferisco al cambiamento dei codici ereg ecc...) non riesco a gestirlo da solo, ho provato, ma nulla, quindi cortesemente se possibile avrei bisogno di un aiuto nel convertire le poche stringhe del file.
allego il codice che ho necessità di trasformare, se qualcuno può darmi una mano sarei molto grato. grazie.
<?
class Template {
var $template_file,
$buffer,
$foreach,
$content,
$debug;
function Template($filename,$debug = "") {
$this->template_file = $filename;
$this->debug = $debug;
$fp = fopen ($filename, "r");
$this->buffer = fread($fp, filesize($filename));
fclose($fp);
$i=0;
do {
$result = ereg("<\[foreach\]>(.+)<\[\/foreach\]>",$this->buffer,$token);
if ($result) {
$this->foreach[] = $token[1];
$this->buffer = ereg_replace("<\[foreach\]>.+<\[\/foreach\]>","<[foreach$i]>",$this->buffer);
}
} while ($result);
}
function setContent($name, $value) {
$this->content[$name][] = $value;
}
function setContent2($name, $value = "") {
if (gettype($name) == "array") {
foreach($name as $k => $v) {
$this->content[$k][] = $v;
}
} else {
$this->content[$name][] = $value;
}
}
function pre($var) {
if ($this->debug == "DEBUG") {
return "<!- begin:$var -->";
}
}
function post($var) {
if ($this->debug == "DEBUG") {
return "<!- end:$var -->";
}
}
function parse() {
if ($this->debug == "DEBUG") {
$pre = "<!- \$token[1] -->";
$post = "<!- \$token[1] -->";
}
for($i=0;$i<count($this->foreach);$i++) {
$result = ereg("<\[([[:alnum:]]+)\]>",$this->foreach[$i],$token);
if ($result) {
$iterations = count($this->content[$token[1]]);
}
for ($j=0;$j<$iterations;$j++) {
$buffer = $this->foreach[$i];
do {
$result = ereg("<\[([[:alnum:]]+)\]>",$buffer,$token);
if ($result) {
$buffer = ereg_replace("<\[$token[1]\]>",$this->pre($token[1]).$this->content[$token[1]][$j].$this->post($token[1]),$buffer);
}
} while ($result);
$this->content["foreach$i"][0] .= $buffer;
}
}
do {
$result = ereg("<\[([[:alnum:]]+)\]>",$this->buffer,$token);
if ($result) {
$this->buffer = ereg_replace("<\[$token[1]\]>",$this->pre($token[1]).$this->content[$token[1]][0].$this->post($token[1]),$this->buffer);
}
} while ($result);
}
function close() {
echo $this->buffer;
}
function get() {
return $this->buffer;
}
}
?>