Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Wyrażenie regularne, problem ..
ciniutek
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 29.05.2011

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


Witam . Mam pewien problem z wyrażeniem regularnym . Dokładnie to z wyciągnięciem pewnej treści .. Mam do wyciągnięcia dwie linijki kodu :

  1. <div style="cursor: pointer;" id="menuc286">tytuł</div>
  2. <div style='display: none;' class='hideit menuh286'>


Próbowałem stosować już \n ale nic nie daje ..
A oto kawałek mojego skryptu :

  1. $regexp = "<div style=\"cursor: pointer;\" id=\"(.*)\">(.*)<\/div>";
  2. if(preg_match_all("/$regexp/", $nowe, $matches, PREG_SET_ORDER)) {
  3. foreach($matches as $match)
Go to the top of the page
+Quote Post
tolomei
post
Post #2





Grupa: Zarejestrowani
Postów: 450
Pomógł: 135
Dołączył: 18.11.2010
Skąd: Wschowa

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


To co podałeś działa dla mnie bez zarzutu.
Może z pętlą foreach coś nie tak było?
Odpal sobie to:

  1. $text = '<div style="cursor: pointer;" id="menuc286">tytuł</div>
  2. <div style=\'display: none;\' class=\'hideit menuh286\'>
  3. <div style="cursor: pointer;" id="abcd">12345</div>
  4. <div style=\'display: none;\' class=\'hideit menuh286\'>';
  5.  
  6. $regexp = "<div style=\"cursor: pointer;\" id=\"(.*)\">(.*)<\/div>";
  7. if(preg_match_all("/$regexp/", $text, $matches, PREG_SET_ORDER)) {
  8. var_dump($matches);
  9. }


A co takiego chciałeś z drugiej linijki wyciągnąć ?
Czy chciałeś ją po prostu odnaleźć ?


--------------------
“ Computers are good at following instructions, but not at reading your mind. ”
- Donald Knuth
Go to the top of the page
+Quote Post
ciniutek
post
Post #3





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 29.05.2011

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


Chodzi o to , że chce wyciągnąć większy kawałek kodu ze źródła pewnej strony smile.gif
  1. <div style="cursor: pointer;" id="menuc286">Tytuł</div> //TUTAJ JEST "ENTER"
  2.  
  3. <div style='display: none;' class='hideit menuh286'><tr><td><table cellpadding='0' cellspacing='0' border='0' width=0%' align='center'><tr><td><a href='Link' target='_blank'>


Ten pierwszy kawałek z tytułem bez problemowo mi wyciąga , ale jak już dodaje drugą linijkę , to już nic się nie wyświetla w tablicy ..

W manualu widziałem takie zastosowanie :

  1. $regexp = ("<div style=\"cursor: pointer;\" id=\"(.*)\">(.*)<\/div>", "<div style='display: none;' class='hideit menuh286'><tr><td><table cellpadding='0' cellspacing='0' border='0' width=0%' align='center'><tr><td><a href='Link' target='_blank'>");


Ale wyskakuje błąd "," ..

Ten post edytował ciniutek 19.08.2011, 09:14:25
Go to the top of the page
+Quote Post
sada
post
Post #4





Grupa: Zarejestrowani
Postów: 302
Pomógł: 24
Dołączył: 6.12.2008

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


Skoro między linijkami jest enter musisz dodać między wzorcami tych linijek biały znak np: \n
Go to the top of the page
+Quote Post
ciniutek
post
Post #5





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 29.05.2011

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


Dodawałem , ale nic nie daje .. chyba , że źle jakoś dodaje ..

  1. $regexp = ("<div style=\"cursor: pointer;\" id=\"(.*)\">(.*)<\/div>\n<div style='display: none;' class='(.*)'><tr><td><table cellpadding='0' cellspacing='0' border='0' width=0%' align='center'><tr><td><a href='(.*)' target='_blank'>");
  2. if(preg_match_all("/$regexp/", $nowe, $matches, PREG_SET_ORDER)) {
  3. foreach($matches as $match)
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 Aktualny czas: 19.08.2025 - 16:14