Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wyrażenia regularne, Class Template
lDoran
post
Post #1





Grupa: Zarejestrowani
Postów: 172
Pomógł: 13
Dołączył: 15.11.2009

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


Witam mam problem ze zrozumieniem poniżej zamieszczonej metody, a dokładnie jak działa wyrażenie: '/{([^}]+)}/e' oraz '$this->dane["\\1"]'
  1. function execute() {
  2. return preg_replace('/{([^}]+)}/e', '$this->dane["\\1"]',
  3. $this->tmpl);
  4. }


Poniżej zamieszczam pełną klasę:
  1. <?php
  2. class Template {
  3. var $tmpl;
  4. var $dane;
  5.  
  6. function Template ($name)
  7. {
  8. $this->tmpl = implode('', file($name));
  9. $this->dane = Array();
  10. }
  11.  
  12. function add($name, $value = '')
  13. {
  14. if (is_array($name)) {
  15. $this->dane = array_merge($this->dane, $name);
  16. } else if (!empty($value)) {
  17. $this->dane[$name] = $value;
  18. }
  19. }
  20.  
  21. function execute() {
  22. return preg_replace('/{([^}]+)}/e', '$this->dane["\\1"]',
  23. $this->tmpl);
  24. }
  25.  
  26. }
  27. ?>


Skrypt pochodzi ze strony: http://www.programuj.com/artykuly/www/template.php
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.12.2025 - 07:05