Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Szablon...
ActivePlayer
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 1 224
Pomógł: 40
Dołączył: 6.07.2004
Skąd: Wuppertal

Ostrzeżenie: (0%)
-----


index.php
  1. <?
  2. include (&#092;"parser.php\");
  3. $tpl = new template;
  4. $tpl -> load(index.tpl);
  5. $tpl -> blocks = array(
  6. &#092;"TYTOL\" => \"Moja pierwsza strona z szablonami\",
  7. &#092;"MENU\" => \"DUPA\",
  8. &#092;"TRESC\" => \"hohohoho dziala:)\"
  9. );
  10. $tpl->parse();
  11. echo $tpl->parsed;
  12. ?>


index.tpl
  1. <?php
  2.  
  3. <html>
  4. <head>
  5. <TITLE>{TYTOL}</TITLE>
  6. </head>
  7. <body>
  8. <table>
  9. <tr><td>{MENU}</td><td>{TRESC}</td></tr>
  10. <table>
  11. </body>
  12. </html>
  13.  
  14. ?>


parser.php
  1. <?
  2. class template
  3. {
  4.    var $unparsed = array(0 => '');
  5.    var $parsed = '';
  6.    var $blocks = array('default' => '');
  7.  
  8.  function load($plik)
  9.    {
  10.       $this -> unparsed = @file($plik);
  11.    }
  12.   function parse()
  13.    {
  14.       $this -> parsed = &#092;"\";
  15.       $cnt = count($this -> unparsed);
  16.       for($i = 0; $i <= $cnt; $i++)
  17.       {
  18.          $tekst = $this -> unparsed[$i];
  19.          $found = array();
  20.          if(preg_match_all(&#092;"#{(.+?)}#is\", $tekst, $found))
  21.          {
  22.             foreach($found[1] as $block)
  23.             {
  24.                $block_names[] = '{'.$block.'}';
  25.                $block_values[] = &$this -> blocks[$block]; 
  26.             }
  27.             $tekst = str_replace($block_names, $block_values, $tekst);
  28.          }
  29.          $this -> parsed .= $tekst;
  30.       }
  31.    }
  32. }
  33. ?>


Moja glupota... juz dziala ;/

Ten post edytował ActivePlayer 6.07.2004, 22:59:00
Go to the top of the page
+Quote Post

Posty w temacie
- ActivePlayer   Szablon...   6.07.2004, 22:52:06


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: 27.12.2025 - 00:16