Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z Parserem....
keedy
post
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 18.12.2003
Skąd: Gliwice

Ostrzeżenie: (10%)
X----


mam taką funckje:

  1. <?php
  2.  
  3. public function display( $strFile ) {
  4. $resFile = fopen( $this->strTemplateDir . '/' . $strFile, 'r' );
  5. $strBuff = fread( $resFile, filesize( $this->strTemplateDir . '/' . $strFile ) );
  6. foreach( $this->arrVars as $strVar => $strValue ) {
  7. $strOutput = str_replace( $this->strBeginTag . '$' . $strVar . $this->strEndTag, $strValue, $strBuff );
  8. }
  9. echo $strOutput;
  10. }?>


Otóz jak widac zmienna $strOutput jest za kazdą petlą foreach jest nadpisywana, jak rozwiązac ten problem, aby zmienna nei byla nadpisywana?

Ten post edytował keedy 12.02.2005, 21:01:28
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
keedy
post
Post #2





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 18.12.2003
Skąd: Gliwice

Ostrzeżenie: (10%)
X----


Moze dla ułatwienia podam cały kod:
  1. <?php
  2.  
  3. class Template {
  4.  
  5. public $strTemplateDir = './templates/2';
  6. public $strBeginTag = '{';
  7. public $strEndTag = '}';
  8. public $arrVars = array();
  9.  
  10. private function __contruct() {}
  11.  
  12. public function assign( $strVar, $strValue ) {
  13. $this->arrVars[$strVar] = $strValue;
  14. }
  15.  
  16. public function display( $strFile ) {
  17. $resFile = fopen( $this->strTemplateDir . '/' . $strFile, 'r' );
  18. $strBuff = fread( $resFile, filesize( $this->strTemplateDir . '/' . $strFile ) );
  19. foreach( $this->arrVars as $strVar => $strValue ) {
  20. $strOutput = str_replace( $this->strBeginTag . '$' . $strVar . $this->strEndTag, $strValue, $strBuff );
  21. }
  22. echo $strOutput;
  23. }
  24. }
  25.  
  26. $tpl = new Template;
  27. $tpl->assign( 'Time', 'test' );
  28. $tpl->assign( 'Dwa', 'test-2' );
  29. $tpl->assign( 'Dwaq', 'test-2' );
  30. echo $tpl->display( 'index.tpl' );
  31. ?>
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: 14.10.2025 - 23:14