Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] problem z preg_match();
moto0095
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Witam, mam problem z ułożeniem odpowiedniego wyrażenia do preg_match();
Mam o to taki kod HTML:
  1. | <a href="index.html?akcja=cośtam&amp;page=TO">&gt;&gt;</a> |

I potrzebuje wyciągnąć tylko "page=".
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
mat-bi
post
Post #2





Grupa: Zarejestrowani
Postów: 690
Pomógł: 92
Dołączył: 6.02.2011

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


eee, $_GET['page'] ?

Czekaj, chyba ogarniam.

<a href="index.html?akcja=(.*)&page=(.*)">(.*)<\/a>?

Ten post edytował mat-bi 2.08.2011, 20:37:31
Go to the top of the page
+Quote Post
moto0095
post
Post #3





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Nie o to mi chodzi,
  1. $fp = file_get_contents('jakaś tam domena');
  2. preg_match(i tutaj nie wiem co wpisać, $fp, $ils);

I z inne strony z o to takiej części kodu
  1. | <a href="index.html?akcja=cośtam&amp;page=TO">&gt;&gt;</a> |

chcę wydobyć tylko "TO"

Próbuje tak
  1. preg_match("# | <a href="index.html?akcja=cośtam&amp;page=(.*?)">&gt;&gt;</a> | #", $fp, $ils);

ale nie działa
Go to the top of the page
+Quote Post
Piogola
post
Post #4





Grupa: Zarejestrowani
Postów: 151
Pomógł: 36
Dołączył: 1.02.2011
Skąd: Warszawa

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


  1. preg_match('# | <a href="index\.html\?akcja=cośtam&amp;page=(.*?)">&gt;&gt;</a> | #', $fp, $ils);
Go to the top of the page
+Quote Post
moto0095
post
Post #5





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


@Piogola niestety nie działa (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
bastard13
post
Post #6





Grupa: Zarejestrowani
Postów: 664
Pomógł: 169
Dołączył: 8.01.2010
Skąd: Kraków

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


  1. $fp = file_get_contents('jakaś tam domena');
  2. $pattern = '/\| <a href="index\.html\?akcja=cośtam&amp;page=([a-z]+)">&gt;&gt;<\/a> \| /i';
  3. preg_match($pattern, $fp, $ils);

lub coś w tym stylu.
Ogólnie chodzi o ujęcie fragmentu, który chcesz wydobyć w nawiasy okrągłe.
Tu masz przykłady:
http://www.php.net/manual/en/function.preg-match.php
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: 20.12.2025 - 14:14