Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Tylko jeden element z tablicy
WebKing
post
Post #1





Grupa: Zarejestrowani
Postów: 219
Pomógł: 16
Dołączył: 16.07.2007

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


Cześć,
Mam problem pokaże wam kod i wytłumaczę:

Plik index.php:
  1. <?php
  2. class Template {
  3.    public $template;
  4.  
  5.    function load($file) {
  6.        $this->template = file_get_contents($file);
  7.    }
  8.  
  9.    function vars($array) {
  10.        foreach($array as $key => $val) {
  11.            $temp = str_replace($key, $val, $this->template);
  12.        }
  13.        $this->template = $temp;
  14.    }
  15.  
  16.    function generate() {
  17.        echo $this->template;
  18.    }
  19. }
  20.  
  21. $template = new Template;
  22. $template->load("template.html");
  23. $template->vars(array(
  24.    "TITLE" => "tytul",
  25.    "CONTENT" => "cosblabla"
  26. ));
  27. $template->generate();
  28. ?>


Plik template.html:
  1. <b>TITLE</b>:CONTENT


Problem jest taki że wyświetla się tylko ostatni element tablicy czyli w tym wypadku CONTENT inne są olewane. Proszę o pomoc, z góry dziękuje za odpowiedź.
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 21.08.2025 - 22:55