Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem z wyrażeniami regularnymi
DeWo
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 12.01.2011

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


Hej!

Mam mały problem. Piszę właśnie kawałek kodu który musi wyciąnąć z:
Kod
przed
<!-- message -->
Tekst 1
Czesc 2
<!-- / message -->
Po 1
Po 1 / 2
<!-- message -->
Tekst 2
czesc 2
<!-- / message -->
Po 2
Po 2 / 2

Po
do tablicy:
Kod
[0] => <!-- message -->
Tekst 1
Czesc 2
<!-- / message -->
[1] => <!-- message -->
Tekst 2
czesc 2
<!-- / message -->



Próbowałem takiej regułki:
Kod
preg_match_all('(<!\-\-\smessage\s\-\->.?<!\-\-\s\/\smessage\s\-\->)', $textarea, $wyjscie);

ale jak mogłem się spodziewać nie działa. Wyrażenia regularne nigdy nie były moją mocną stroną (IMG:style_emoticons/default/winksmiley.jpg)

Proszę Was o napisanie działającej reguły do preg_match_all (IMG:style_emoticons/default/smile.gif)

Z góry thx
DeWo

Ten post edytował DeWo 13.01.2011, 10:48:39
Go to the top of the page
+Quote Post
flashdev
post
Post #2





Grupa: Zarejestrowani
Postów: 812
Pomógł: 117
Dołączył: 2.12.2008

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


Dodaj flagę m (multiline):

Kod
'/twoja-regula/m'


I zamiast '?' użyj gwiazdki '*'.
Go to the top of the page
+Quote Post
DeWo
post
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 12.01.2011

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


Cytat(flashdev @ 13.01.2011, 10:58:39 ) *
Dodaj flagę m (multiline):

Kod
'/twoja-regula/m'


I zamiast '?' użyj gwiazdki '*'.


  1. preg_match_all('/<!\-\-\smessage\s\-\->.*<!\-\-\s\/\smessage\s\-\->/m', $textarea, $wyjscie);


Kod
Array
(
    [0] => Array
        (
        )

)


(IMG:style_emoticons/default/worriedsmiley.gif) help (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
3lanc
post
Post #4





Grupa: Zarejestrowani
Postów: 30
Pomógł: 5
Dołączył: 13.01.2011

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


  1. <?php
  2. $src = "<!-- message -->
  3. Tekst 1
  4. Czesc 2
  5. <!-- / message -->
  6. Po 1
  7. Po 1 / 2
  8. <!-- message -->
  9. Tekst 2
  10. czesc 2
  11. <!-- / message -->";
  12.  
  13. echo $src;
  14.  
  15. preg_match_all("/<!\-\- message \-\->(.*?)<!\-\- \/ message \-\->/sim", $src, $msg);
  16.  
  17. print_r($msg);
  18. ?>


Tablica

  1. (
  2. [0] => Array
  3. (
  4. [0] => <!-- message -->
  5. Tekst 1
  6. Czesc 2
  7. <!-- / message -->
  8. [1] => <!-- message -->
  9. Tekst 2
  10. czesc 2
  11. <!-- / message -->
  12. )
  13.  
  14. [1] => Array
  15. (
  16. [0] =>
  17. Tekst 1
  18. Czesc 2
  19.  
  20. [1] =>
  21. Tekst 2
  22. czesc 2
  23.  
  24. )
  25.  
  26. )
Go to the top of the page
+Quote Post
DeWo
post
Post #5





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 12.01.2011

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


Wielkie dzięki (IMG:style_emoticons/default/smile.gif)

Łap "Pomógł" (IMG:style_emoticons/default/winksmiley.jpg)

Wielkie dzięki (IMG:style_emoticons/default/smile.gif)

Łap "Pomógł" (IMG:style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post

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: 23.08.2025 - 07:18