Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dlaczego preg_replace nie podmienia?
deirathe
post
Post #1





Grupa: Zarejestrowani
Postów: 426
Pomógł: 32
Dołączył: 24.05.2007

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


  1. <?php
  2. class template{
  3.  
  4. private $file;
  5. public $tpl;
  6. public $vars;
  7. public $queries;
  8.  
  9.  
  10. public function __construct($file){
  11. if(!file_exists($file)) exit("Plik $file nie istnieje");
  12. $this->file = $file;
  13. $this->tpl = fread(fopen($this->file,r),filesize($this->file));
  14. }
  15. public function put($var_name,$var_value){
  16. if(!$var_name) exit("W przekazywanej wartości nie została podana nazwa");
  17. $this->vars[$var_name] = $var_value;
  18. }
  19.  
  20. public function getVar($var_name){
  21. echo $var_name;
  22. return $this->vars[$var_name];
  23. }
  24. public function parse(){
  25. preg_match_all('/<template.*>[w|W]*</template>/U',$this->tpl,$this->queries);
  26. echo preg_replace('/<template.*>(w+)</template>/U',$this->vars["$1"],$this->tpl);
  27. }
  28.  
  29.  
  30.  
  31. }
  32. ?>

mam taką klasę (jak powyżej)- w sumie to jest dopiero początek klasy. Problem tkwi w tym, ęe preg_replace nie podminenia mi zmiennych z obiektu utworzonego z tej klasy na tekst znajdujący się pomiędzy znacznikami template w tym oto templaku:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  4. <title>Untitled Document</title>
  5. </head>
  6.  
  7. <template action="loop">nazwa</template>
  8. <template action="show">nazwa2</template>
  9.  
  10. </body>
  11. </html>

Kod który tworzy obiekt i dodaje zmienne:
  1. <?php
  2.  
  3. require_once("template.class.php");
  4.  
  5.  
  6.  
  7. $tpl = new template("tpls/file.tpl");
  8.  
  9. $tpl->put("nazwa","moja nazwa");
  10. $tpl->put("nazwa2","moja nazwa2");
  11. $tpl->parse();
  12.  
  13.  
  14.  
  15.  
  16. ?>

Jakieś idee?
P.S. nie patrzcie na te błędne slashe forum je samo dodało

Ktokolwiek może pomóc?

Ten post edytował deirathe 28.06.2007, 14:22:07


--------------------
Kawałek mojego blogu
Everything should be as simple as possible but not simpler.
A Einstein
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: 22.08.2025 - 09:34