Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wyr. regularne i bardziej skomplikowany ciąg, preg_replace
czachor
post
Post #1





Grupa: Zarejestrowani
Postów: 897
Pomógł: 40
Dołączył: 16.12.2003
Skąd: Warszawa

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


Wtam! Mam taki kod:
  1. <?php
  2. class change
  3. {
  4. var $string;
  5. var $result;
  6. var $vars;
  7.  
  8. function change($string)
  9. {
  10. $this -> string = $string;
  11. $this -> result = NULL;
  12. $this -> vars = array();
  13. }
  14.  
  15.  
  16. function replace()
  17. {
  18. $this -> result = preg_replace(&#092;"/{(S+)}/e\", \"$this-> 1\", $this -> string);
  19. echo $this -> result;
  20. }
  21.  
  22.  
  23. function insert_var($name, $value)
  24. {
  25. $this -> {$name} = $value;
  26. }
  27. };
  28.  
  29. //Przykład użycia
  30. $string = 'Cześć {name} co porabiasz w {day}';
  31.  
  32. $change = new change($string);
  33. $change -> insert_var('name', 'Waluś'); //wstawienie wartości zmiennych
  34. $change -> insert_var('day', 'środę');
  35. $change -> replace();
  36. //Zwróci oczywiście
  37. //Cześć Waluś co porabiasz w środę
  38. ?>

Niestety przy ciągach typu
Kod
Cześć} } {name4} bl{name} a{ df {name22} {{{sdf} {blah}
całość się wywala... W wyrażeniach regularnych jestem jeszcze słaby, dlatego proszę o Waszą pomoc, w jaki sposób przetworzyć podany string... ohmy.gif
Z góry dzięki!


--------------------
how many SEO experts does it take to change a light bulb,lightbulb,light,bulb,lamp,lighting,switch,sex,xxx
5-Reasons-why-you-should-NEVER-fix-a-computer-for-free
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 - 15:02