Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] podstawienie php za html
Lee
post
Post #1





Grupa: Zarejestrowani
Postów: 319
Pomógł: 0
Dołączył: 11.04.2006
Skąd: Chojnów

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


Mam taki kod
  1. <?php
  2. $szablon = file_get_contents("./theme/Classic/news.tpl");
  3. $szablon = preg_replace('/{(.*?)}/si', "$$1", $szablon);
  4. echo $szablon;
  5. ?>

który podstawia mi zamiast np {title} tekst $title (w tym echo $szablon pokazuje mi $title jako tekst a nie zawartosć zmiennej $title)

no i jak włąsnie zrobić, żeby przetowrzyło mi {title} na $title, ale zamiast tego $title wyświetliło mi jej zawartosć (np Moja Strona)

pozdrawiam (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Lee
post
Post #2





Grupa: Zarejestrowani
Postów: 319
Pomógł: 0
Dołączył: 11.04.2006
Skąd: Chojnów

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


no tak ale mój kod łatwo obiektowo przerobić (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) chociarz ten już też przerobiłęm (funkcje) - nie obrazisz się chyba jak go wykorzystam (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) ?

przerobiony kod jak by ktoś chciał (odrazu jako klasa (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) )
  1. <?php
  2.  
  3. final class template{
  4. public $parse_size;
  5. public $parse_handler;
  6. public $parse_value;
  7. public $pre_key;
  8. public $pre_code;
  9. public $converted;
  10.  
  11. public function parser($parse_file, $parse_array = array())
  12. {
  13. if(is_file($parse_file))
  14. {
  15. $this -> parse_size = filesize($parse_file);
  16.  
  17. if($this -> parse_size < 1)
  18. {
  19. $this -> parse_size = 1;
  20. }
  21.  
  22. $this -> parse_handler = fopen($parse_file, "r");
  23. $this -> parse_value = fread($this -> parse_handler, $this -> parse_size);
  24.  
  25. foreach($parse_array as $this -> pre_code => $this -> pre_key)
  26. {
  27. $this -> parse_value = str_replace('{'.$this -> pre_code.'}', $this -> pre_key, $this -> parse_value);
  28. }
  29.  
  30. fclose($this -> parse_handler);
  31.  
  32. $this -> converted = $this -> parse_value;
  33. }
  34. else
  35. {
  36. $this -> converted = 'Nie mogę odnaleźć pliku '.$this -> parse_file.'!';
  37. }
  38.  
  39. return $this -> converted;
  40. }
  41. }
  42.  
  43. $template = new template;
  44.  
  45. ?>
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: 10.10.2025 - 05:04