Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Regexp - problem
bronchos
post
Post #1





Grupa: Zarejestrowani
Postów: 25
Pomógł: 0
Dołączył: 16.03.2007

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


  1. <?php
  2. $text = "wiersz 1 - {IF 'alabama'=='ggg'}equal{ELSEIF 'alabama'=='hhh'}not 1{ELSEIF 'alabama'=='fff'}not 2{ELSE}not 3{ENDIF}";
  3.  
  4. preg_match('/({IF (.*?)}(.*?))({ELSEIF (.*?)}(.*?))*({ELSE}(.*?))?({ENDIF})/s',$text,$regs);
  5.  
  6. echo '<pre>';
  7. print_r($regs);
  8. echo '</pre>';
  9. ?>


Powyższy kod działa nie do końca tak, jakbym chciał. Zamiast wyłapać wszystkie powtórzenia "{ELSEIF ddd}ddd" łapie tylko ostatnie wystąpienie.

Innymi słowy, zamiast:
  1. Array
  2. (
  3. [0] => {IF 'alabama'=='ggg'}equal{ELSEIF 'alabama'=='hhh'}not 1{ELSEIF 'alabama'=='fff'}not 2{ELSE}not 3{ENDIF}
  4. [1] => {IF 'alabama'=='ggg'}equal
  5. [2] => 'alabama'=='ggg'
  6. [3] => equal
  7. [4] => {ELSEIF 'alabama'=='fff'}not 2
  8. [5] => 'alabama'=='fff'
  9. [6] => not 2
  10. [7] => {ELSE}not 3
  11. [8] => not 3
  12. [9] => {ENDIF}
  13. )


oczekuję rezultatu:
  1. Array
  2. (
  3. [0] => {IF 'alabama'=='ggg'}equal{ELSEIF 'alabama'=='hhh'}not 1{ELSEIF 'alabama'=='fff'}not 2{ELSE}not 3{ENDIF}
  4. [1] => {IF 'alabama'=='ggg'}equal
  5. [2] => 'alabama'=='ggg'
  6. [3] => equal
  7. [4] => {ELSEIF 'alabama'=='hhh'}not 1
  8. [5] => 'alabama'=='hhh'
  9. [6] => not 1
  10. [7] => {ELSEIF 'alabama'=='fff'}not 2
  11. [8] => 'alabama'=='fff'
  12. [9] => not 2
  13. [10] => {ELSE}not 3
  14. [11] => not 3
  15. [12] => {ENDIF}
  16. )


Macie może pomysł jak to zmienić?

Z góry dzięki,
MS
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 - 00:31