Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Preg_match, Pomoc w wyrażeniu regularnym
Sean Foster
post 13.04.2010, 12:56:01
Post #1





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

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


Jak za pomocą wyrażeń regularnych wyciągnąć adres url questionmark.gif
  1. <tr><td>21</td>
  2. <td>
  3. <a href="wyzwij/5609/bua/">


Próbowałem tak:
  1. preg_match('/<tr><td>21<\/td>
  2. <td>
  3. <a href="([a-zA-Z0-9\.\-\_]+)">/', $curl, $adres);
  4.  
  5. print_r($adres);
  6. //lub
  7. preg_match('/<tr><td>21<\/td> \n
  8. <td> \n
  9. <a href="([a-zA-Z0-9\.\-\_]+)">/', $curl, $adres);
  10. //lub
  11. preg_match('/<tr><td>21<\/td>
  12. <td>
  13. <a href="[a-zA-Z0-9\.\-\_]">/', $curl, $adres);


Ale jedynym wynikiem było
Kod
Array
(
)
lub

Array


Z góry dziękuję.

Go to the top of the page
+Quote Post
skw
post 13.04.2010, 13:19:01
Post #2





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 14.11.2008

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


U mnie zadziałało to:
  1. preg_match('|<tr><td>21</td>
  2. <td>
  3. <a href="([a-zA-Z0-9\.\-\_/]{1,})|', $curl, $adres);
Go to the top of the page
+Quote Post
Sean Foster
post 13.04.2010, 13:26:44
Post #3





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

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


Mi wychodzi
Kod
Array
(
    [0] => 21


Mam hosting na koon.pl
Go to the top of the page
+Quote Post
prochniak
post 13.04.2010, 13:30:14
Post #4





Grupa: Zarejestrowani
Postów: 15
Pomógł: 1
Dołączył: 3.02.2010
Skąd: Warszawa

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


  1. <?php
  2. $a = '<tr><td>21</td>
  3. <td>
  4. <a href="wyzwij/5609/bua/">';
  5.  
  6. preg_match('<a href="([a-zA-Z0-9\.\-\_/]{1,})">',$a,$b);
  7. print_r($b[1]);
  8.  
  9. ?>
Go to the top of the page
+Quote Post
Pawel_W
post 13.04.2010, 13:37:50
Post #5





Grupa: Zarejestrowani
Postów: 1 675
Pomógł: 286
Dołączył: 15.06.2009
Skąd: Wieliczka

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


dobra, a co jak adres będzie zawierał http:// ? wtedy go nie wyciągnie...

  1. preg_match('href="([^"]+)">',$a,$b);
Go to the top of the page
+Quote Post
Sean Foster
post 13.04.2010, 13:38:44
Post #6





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

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


Cytat(prochniak @ 13.04.2010, 14:30:14 ) *
  1. <?php
  2. $a = '<tr><td>21</td>
  3. <td>
  4. <a href="wyzwij/5609/bua/">';
  5.  
  6. preg_match('<a href="([a-zA-Z0-9\.\-\_/]{1,})">',$a,$b);
  7. print_r($b[1]);
  8.  
  9. ?>


Dzięki za pomoc, musiałem trochę to zmodyfikować bo gdy zamiast $a podsunąłem stronę którą chcę parsować wywalało mi z 50 linków. Zrobiłem tak:
  1. preg_match_all('<a href="wyzwij/([a-zA-Z0-9\.\-\_/]{1,})">',$pvp_curl,$b);

i tak jest dobrze, bo mój link jest zawsze 20

@Pawel_W
Linki zawsze będą wyglądać j.w. bez http://

Ten post edytował Sean Foster 13.04.2010, 13:43:47
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 16.06.2025 - 21:15