Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Parser szablonów
akurczyk
post
Post #1





Grupa: Zarejestrowani
Postów: 201
Pomógł: 5
Dołączył: 15.07.2008
Skąd: Kłodzko

Ostrzeżenie: (10%)
X----


Napisałem parser szablonów.
index.php:
  1. <?php
  2. class template {
  3. var $sSource;
  4. var $sParsed;
  5. var $aValues = array();
  6. function load($sTemplate) {
  7. return (!$this->sSource = @file_get_contents($sTemplate)) ? false : true;
  8. }
  9. function init($sKey, $sValue) {
  10. $this->aValues[$sKey] = $sValue;
  11. }
  12. function run() {
  13. print preg_replace('/{(.+?)}/e', '$this->aValues['1']', $this->sSource);
  14. }
  15. }
  16. $tpl = new template;
  17. $tpl -> load("template.html");
  18. $tpl -> init("{TITLE}", "Tytuł strony");
  19. $tpl -> init("{CONTENT}", "Treść strony");
  20. $tpl -> run();
  21. ?>


template.html:
  1. <title>{TITLE}</title>
  2. </head>
  3. {CONTENT}
  4. </body>
  5. </html>


Dlaczego to niechce działać?
Co napisałem źle?

Ten post edytował akurczyk 16.07.2008, 10:18:18
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 18:22