# PHP Template help

**URL:** <https://forum.kirupa.com/t/php-template-help/111791>\
**Category:** Uncategorized\
**Created:** [May 31, 2004, 9:53am UTC](https://forum.kirupa.com/t/php-template-help/111791 "2004-05-31T09:53:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![b0b0](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@b0b0](https://forum.kirupa.com/u/b0b0)\
**Post date:** [May 31, 2004, 9:53am UTC](https://forum.kirupa.com/t/php-template-help/111791/1 "2004-05-31T09:53:59Z")

</div>

HI!  
For a school project we had to make a dynamic web page, and seperate server-side code with client-side code.

So i googled for different solutions and found different templates like smarty and such, but they where all verry complicated. I found one, that was easy to use, with a couple of changes I got the desired easy template.

**Though here’s the problem**. How can I make php loop a certain part of the template file\*\*???\*\*

heres my “mixer” that sets the parameter:

```auto
<?php
class Page
{
var $page;

function Page($template = '') {
if (file_exists($template))
$this->page = join('', file($template));
else
die("Template file $template not found.");
}

function parse($file) {
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}

function replace_tags($tags = array()) {
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
$data = (file_exists($data)) ? $this->parse($data) :
$data;
$this->page = eregi_replace('--' . $tag . '--', $data,
$this->page);
}
else
die('No tags designated for replacement.');
}

function output() {
print($this->page);
}
}
?> 

```

and here’s the output file:

```auto
<?php 
require_once('phpmixer.php');
$db = mysql_connect("host","DB_name","password"); 
mysql_select_db ("db_name") or die ("Cannot connect to database"); 

$query = "SELECT title, description, web, author, date, email FROM tuts ORDER BY id DESC";
$result = mysql_query($query); 

/* fetch the result as an array */ 

while($r=mysql_fetch_array($result)) {    

 $page = new Page('view.htm');
 
    $title=$r['title'];
    $description=$r["description"]; 
    $webpage=$r["web"]; 
    $author=$r["author"]; 
    $email=$r["email"]; 
    $date=$r["date"];     

$page->replace_tags(array(
'title' => $title,
'description' => $description,
'web' => $webpage,
'email' => $email,
'author' => $author,
'date' => $date));

$page->output();
}
mysql_close($db); 

?>

```

The html page has tags like these “–title–” where the desired content fits!

I hope someone can help me, if not, I hope someone can get some help from the code 😉

Thanx in advance!
