Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyrażenia regularne i wyciągnięcie danych ze stringu
mickula
post
Post #1





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 28.10.2006

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


Witam,

mam oto taki tekścik:

Feb 19 2008, 16:49:22 CET went out 80 times with Isabell
and with Ressco

muszę z tego wyciągnąć rzeczy pogrubione: datę, ilość razy, i dwa imiona.
Ktos pomoże? Nigdy nie byłem mocny w wyrażeniach regularnych.
Z góry dziękuje.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
bim2
post
Post #2





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


  1. <?php
  2. $string2 = 'Feb 19 2008, 16:49:22 CET went out 80 times with Isabell
  3. and with Ressco';
  4. $string_ = preg_replace('!(.*) went out ([0-9]+) times (.*)!is', '$1::$2::$3', $string2);
  5. $string_ = explode('::', $string_);
  6. preg_match_all('!with ([A-Za-z]+)!', $string_[2], $pregs);
  7. $pregs = $pregs[1];
  8. print_r($string_);
  9. print_r($pregs);
  10. ?>

daje:
Cytat
Array ( [0] => Feb 19 2008, 16:49:22 CET [1] => 80 [2] => with Isabell and with Ressco ) Array ( [0] => Isabell [1] => Ressco )
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: 9.10.2025 - 09:40