hi there.. i m really stuck in this and i cant find a solution.. i m using the "templater parser" function found in a tutorial here in php builder but i need to change it cause it just repeat one region.. and i cant figure out how to put it work...
<?
class template {
var $n_fcontents;
function template ($template_filename, $replacement_rules, $recordset_array,$replacement_repeat)
{
$START_FLAG = 0;
$start_anchor= array();
$end_anchor=0;
$res_arr="";
$fcontents = file ($template_filename);
$count = count($replacemente_repeat);
for($i=0; $i>$count; $i++){
if($i > 0){
$fcontents = $this->n_fcontents;
}
while (list ($line_num, $line) = each ($fcontents))
{
if ($START_FLAG == 0)
{
if (ereg ($replacement_repeat[$i][0], $line))
{
$START_FLAG = 1;
$start_anchor[] = $line_num;
}
}
else
{
if (!ereg ($replacement_repeat[$i][1], $line))
{
$res_arr .= $line;
}
else
{
$START_FLAG = 0;
$end_anchor[] = $line_num;
}
}
}
/* Build String-Replacement Rules ... */
$tmp_res_arr = "";
$n = count($recordset_array);
for ($x=0; $x<$n; $x++)
{
$tmp = $res_arr;
for ($y=0; $y<count($replacement_rules); $y++)
{
$a = $replacement_rules[$y][0];
$b = $replacement_rules[$y][1];
if (ereg ("{", $a))
{
$recordset_array[$x][$b] = stripslashes ($recordset_array[$x][$b]);
eval ("\$tmp = str_replace (\"$a\", \$recordset_array[\$x][$b], \$tmp);");
$tmp = stripslashes($tmp);
}
$tmp_res_arr .= $tmp;
}
}
$res_arr = $tmp_res_arr;
/* Re-constructing the file-contents ... */
$n = count($fcontents);
for ($x=0; $x<$n; $x++)
{
$y = $start_anchor[$i] + ($x - $end_anchor[$i]) ;
if (($x >= $start_anchor[$i]) and ($x < $end_anchor[$i]))
{
if ($this->n_fcontents[$start_anchor[$i]] == "")
$this->n_fcontents[$x] = $res_arr;
}
elseif ($x > $end_anchor[$i])
$this->n_fcontents[$y] = $fcontents[$x];
else
$this->n_fcontents[$x] = $fcontents[$x];
}
}
return ($this->n_fcontents);
} // end function template_parser
}
?>
Dont mind about the mess the function is in... i ve tried so manu things that i dont really know wtf i m doing with it...
I need this function to fill EACH loop of my template file.. and not just one...
I was thinking about using the fuction twice but its gonna have to open the template file 2 or 3 times and its not a good ideia.
I want the function to open the file replale EVERYTHING and then show it.
i tryied to make a replacement_repeat array with this:
<?
$replacement_repeat = array (
array ("<!--start-->","<!--end-->"),
array ("<!--START_ROW-->", "<!--END_ROW-->")
);
?>
But its not working 🙁
Please help 🙁
Here´s the original function and tutorial:
http://www.phpbuilder.com/columns/lep20020402.php3?page=5