Page 1 of 1

PHP Template help

Posted: Thu May 05, 2005 5:37 pm
by Raven-flock
Can someone tell me how would i make a engine or whatever to make this script as it was a Template (or how ever you guys wanna say it)

Code: Select all

<!--!header--><html><head><title>{title}</title><link href=&quote;templates/Classic.css&quote; rel=&quote;stylesheet&quote; type=&quote;text/css&quote;>{headscript}{script}</head><body bgcolor='#000000' text='#CCCCCC'><table border='1' cellpadding=5 cellspacing=0 width='100%'><tr><td colspan=2 class='pageheader'>
<table border=0 cellpadding=0 cellspacing=0 width='100%' class='noborder'><tr><td width='100%' class='noborder'><b>{title}</b></td><td align='right' class='noborder'>{motd}</td></tr></table></td></tr><tr><td width=150 bgcolor='#000066' valign='top' height='100%'>
<table border='0' cellpadding='0' cellspacing='0'>{nav}</table><br>
{mail}<br>
{petition}
</td><td rowspan=2 valign='top' width='100%'>
<!--!footer-->
</td></tr><tr><td width=150 bgcolor='#330000' valign='top'>
{stats}
{paypal}
</td></tr><tr><td colspan=2 bgcolor='#330000' align='center'>

   <table border='0' cellpadding='0' cellspacing='0' width='100%' class='noborder'><tr><td class='noborder'>{copyright}{pagegen}<br/>{version}
   </td><td align='right' class='noborder'>{source}{petition}</td></tr></table>
   </td></tr></table></body></html>
<!--!statstart--><table cellpadding=2 cellspacing=0 class='charinfo' width='150'>
<!--!stathead--><tr><td class='charhead' colspan='2'><b>{title}</b></td></tr>
<!--!statrow--><tr><td class='charinfo'><b>{title}</b></td><td class='charinfo'>`^{value}</td></tr>
<!--!statbuff--><tr><td class='charinfo' colspan='2'><b>{title}:</b>`n{value}</td></tr>
<!--!statend--></table>
<!--!navhead--><tr><td><span class=&quote;navhead&quote;>—{title}—<br></span></td></tr>
<!--!navhelp--><tr><td><span class=&quote;navhelp&quote;>{text}<br></span></td></tr>
<!--!navitem--><tr><td><a href=&quote;{link}&quote;{accesskey}class='nav' {popup}>{text}</a></td></tr>
<!--!login-->
<table width='212' height='234' border='0' cellpadding='0' cellspacing='0' background='images/logindragon.gif' class='noborder'>
   <tr>
       <td valign='bottom' align='center' class='noborder'>
           {username}: <br><input name='name' accesskey='u' size='10'><br>
           {password}:<br><input name='password' accesskey='p' type='password' size='10'><br>
           <input type='submit' value='{button}' class='button'><br>
           <img src='images/trans.gif' width='1' height='37' align='absmiddle' alt=''>
           <img src='images/trans.gif' width='1' height='15'>
       </td>
   </tr>
</table>
this script is from "Legend of the Green Dragon" game
I want to make template kinda like this.. can someone please help me out here..

Thank you
Raven-Flock

Posted: Thu May 05, 2005 9:54 pm
by John Cartwright
first of all, search these boards as this has been covered so so many times.

Basically, it comes to regex'ing your template from file_get_contents()'ing the file and compiling the list of vars which needs to be replaced with any instance of {}.

soo..

In my template class, I would do somehting like

Code: Select all

$template->setvars(array('VAR1' => 'This will replace {VAR1}',
                         'VAR2' => 'This will replace {VAR2}');
as I said erlier, your preg_match() would return as array of strings to be replaced.
Look through your array matching your set vars and str_replace them.