#native_company# #native_desc#
#native_cta#

PHP Templates: Revisited Page 3

By Polerio Babao
on September 9, 2002

Dynamic

This is a bit long. I made this as function because I once tried copy-pasting this code again and again, into a different application, but now I’ve just included it in a class, making call just its class and its function. This is a bit complicated I think. This will parse the date, author and title field.

<?php

function DynamicRows($Prefix=""$LoadTemplate=""$RowName=""$RowValue="")

{

        
// start loopings

        
$tcontent $LoadTemplate;

        
$startlist strpos($tcontent,"<!--%".$Prefix."_BEGIN_MESSAGE_LIST%-->");

        
$endlist strpos($tcontent,"<!--%".$Prefix."_END_MESSAGE_LIST%-->")+28;

        
$listline substr($tcontent,$startlist+30,$endlist-$startlist-58);

        
$listlinetoreplace substr($tcontent,$startlist,$endlist-$startlist);

        
$startlistloop strpos($tcontent,"<!--%".$Prefix."_ML_LOOPBEGIN%-->");

        
$endlistloop strpos($tcontent,"<!--%".$Prefix."_ML_LOOPEND%-->")+22;

        
$listloop 

        
substr($tcontent,$startlistloop+24,$endlistloop-$startlistloop-46);

        $beforeloop substr($listline,0,strpos($listline,"<!--%".$Prefix."_ML_LOOPBEGIN%-->"));

        
$afterloop substr($listline,strpos($listline,"<!--%".$Prefix."_ML_LOOPEND%-->")+22);

        
$newmsgs 0;

        for(
$i=0;$i<count($headers);$i++) {

            if(!
$headers[$i]["read"]) $newmsgs++;

            
$msglist .= eregi_replace("<!--%POLERIODUMMY%-->","Polerio",$beforeloop);

            
$start_pos=0;$end_pos=(count($RowValue));

            for(
$i=$start_pos;$i<$end_pos;$i++) {

                
$thisline "$listlooprn";

                $s_pos=0;$e_pos=count($RowName);

                for(
$j=$s_pos;$j<$e_pos;$j++) {

                    
$thisline eregi_replace($RowName[$j],$RowValue[$i][$j],$thisline);

                }

            }

            
$msglist .= $thisline;

        } 
// end for

        
$msglist .= $afterloop;

        
$tcontent substr($tcontent,0,$startlist).$msglist.substr($tcontent,$endlist,strlen($tcontent));

        
// end loopings

        return $tcontent;

}

?>



1
|
2
|
3
|
4
|
5
|
6
|
7