Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wyrażenie regularne
szczabik
post
Post #1





Grupa: Zarejestrowani
Postów: 226
Pomógł: 1
Dołączył: 13.05.2008

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


Czemu takie wyrażanie zawraca mi w tablicy dwa razy 13 skoro tylko raz występuje ?
  1. <?php
  2. $tekst = 'test test <km>13</km> tetet tet';
  3. $text = preg_match('#<km>(.*?)</km>#si', $tekst, $matches);
  4. print_r($matches);
  5. ?>


Ten post edytował szczabik 29.04.2009, 19:56:29
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
gulldarek
post
Post #2





Grupa: Zarejestrowani
Postów: 156
Pomógł: 15
Dołączył: 13.09.2003
Skąd: London

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


$matches[0] zwraca ci znaleziony ciag ( <km>13</km> ), a $matches[1] konkretny fragment ( 13 ). <km> przegladarka potraktowala jako html, dlatego nie widzisz.

Z dokumentacji:

matches

If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.

http://pl.php.net/preg_match

Ten post edytował gulldarek 29.04.2009, 20:13:13
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: 15.10.2025 - 16:16