RE: BTML 2.0 released!!!
| From: | Rob A. Brahier | Date: | Fri, 07 Nov 2003 13:36:13 +0000 |
| Subject: | RE: BTML 2.0 released!!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-168839@lists.php.net to get a copy of this message | ||
Some comments in the code would be nice too. It's too much of a bother to decipher code
without indentation or comments.
-Rob
-----Original Message-----
From: Bas [mailto:famde.jong@home.nl]
Sent: Thursday, November 06, 2003 10:21 AM
To: php-general@lists.php.net
Subject: BTML 2.0 released!!!
Okay, i am happy that BTML 2.0 is released(finally)
It is also known as BTML Template Edition.
The 3 files(the parser, a simple template and a test BTML-file)
btmltpl.php
---
<?php
function tpl2html($title, $images, $text, $tplfile = "simple.tpl", $links =
"") {
$tpldata = file_get_contents($tplfile);
$trans = array('<%title%>' => $title, '<%text%>' => $text,
'<%images%>' =>
$images, '<%links%>' => $links);
$html = strtr($tpldata, $trans);
return $html;
}
function parseTags($file) {
/* readfile... here */
$filedata = file_get_contents($file);
$tag_match =("!<bttag=(\w*)>\s*(.*?)\s*</bttag>!is");
preg_match_all($tag_match, $filedata, $matches);
for ($i=0; $i< count($matches[0]); $i++) {
$tagname = $matches[1][$i];
$tag['tagname'] = $tagname;
$tag['value'] = $matches[2][$i];
$tags[] = $tag;
}
return $tags;
}
include_once "template.php";
$filename = $_GET['name'];
$bttags = parseTags($filename);
// echo "<HTML><HEAD>";
foreach($bttags as $tag) {
switch($tag['tagname']) {
case 'title':
$title = $tag['value'];
// echo "<TITLE>" . $tag['value'] .
"</TITLE></HEAD><BODY>";
// echo "<H1>" . $tag['value'] . "</h1><br>";
break;
case 'heading':
$completetext .= "<h1>" . $tag['value'] .
"</h1><br>";
// echo "<H1>" . $tag['value'] . "</h1><br>";
break;
case 'image':
if (!empty($tag['value'])) {
// echo "<IMG SRC=\"" . $tag['value'] . "\">";
$images .= "<IMG SRC=\"" . $tag['value'] .
"\"><br>";
}
break;
case 'text':
// echo nl2br($tag['value']);
$completetext .= nl2br($tag['value']);
break;
case 'nl':
// echo "<br>\n";
$completetext .= "<br>";
break;
case 'template':
$templatefile = $tag['value'];
break;
case 'link':
$links .= "<a href=" . $tag['value'] . ">" .
$tag['value'] . "</a><br>"
}
}
// echo "</body></html>";
if (empty($templatefile)) {
echo tpl2html($title, $images, $completetext);
} else {
echo tpl2html($title, $images, $completetext, $templatefile);
}
?>
---
simple.tpl
---
<HTML>
<HEAD><TITLE><%title%></TITLE></HEAD>
<BODY>
<center><h1><%title%></h1></center><br>
<hr>
<%text%><br><br>
Images: <br>
<%images%>
</BODY>
</HTML>
---
And test.btm
---
<bttag=title>
Welcome to BTML page v1!
</bttag>
<bttag=text>
Welcome to my BTML page!!! This is an experimentally version of HTML!!!
<br>Bye!!!
</bttag>
<bttag=nl>
</bttag>
<bttag=heading>
Bye!!!!
</bttag>
---
Hope that you like it and please tell me wat you think of it,
Bas