Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> preg_match i wydobycie tabeli z kodu html
Grzesiek23
post
Post #1





Grupa: Zarejestrowani
Postów: 47
Pomógł: 0
Dołączył: 25.12.2009

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


Pobieram kod html pewnej strony i chciałbym do zmiennej wrzucić jedynie tabelę, która wygląda mniej więcej tak:

...
<table class="messages largepadded">
<trd><td>...</td></tr>
....
</table>
...


Napisałem taką funkcję:

  1. function gettable($page)
  2. {
  3. preg_match("@<table class=\"messages largepadded\">(.*?)<\/table>@i", $page, $w);
  4. return $w[0];
  5. }



Ale przy wywołaniu tej funkcji:

  1. echo(gettable($s));


Otrzymuję błąd:
PHP Notice: Undefined offset: 0 in C:\inetpub\wwwroot\test.php on line 13


Pomoże ktoś?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Grzesiek23
post
Post #2





Grupa: Zarejestrowani
Postów: 47
Pomógł: 0
Dołączył: 25.12.2009

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


Hmm nie wiem czemu, ale dopiero to zadziałało:

  1. function gettable($page)
  2. {
  3. preg_match("#<table ([^>]*)>(.*?)</table>#is", $page, $w);
  4. return $w[0];
  5. }



Mam jeszcze jedną sprawę - jak z tej tabeli, która wygląda tak:

  1. <table class="messages largepadded">
  2. <tr>
  3. <th width="35px">
  4. </th>
  5. <th width="40px">
  6. </th>
  7. <th width="505px">
  8. </th>
  9. <th width="110px">
  10. </th>
  11. </tr>
  12. <tr>
  13. <td>
  14. <input type="checkbox" name="delete_message[]" id="delete_message_88169456" value="88169456" />
  15. </td>
  16. <td>
  17. <img class="icon" src="/images/parts/icon-bell_notifications-empty.gif" alt="Icon-bell_notifications-empty" />
  18. </td>
  19. <td>
  20. <p class="smallpadded">
  21. <a href="/en/citizen/profile/606731">User</a> has transfered 1 PLN to your account.
  22. </p>
  23. </td>
  24. <td>
  25. <span class="fakeheight">one hour ago</span>
  26. </td>
  27. </tr>
  28. <tr>
  29. <td>
  30. <input type="checkbox" name="delete_message[]" id="delete_message_87473700" value="87473700" />
  31. </td>
  32. <td>
  33. <img class="icon" src="/images/parts/icon-bell_notifications-empty.gif" alt="Icon-bell_notifications-empty" />
  34. </td>
  35. <td>
  36. <p class="smallpadded">
  37. Some alert.
  38. </p>
  39. </td>
  40. <td>
  41. <span class="fakeheight">yesterday</span>
  42. </td>
  43. </tr>


Chciałbym, aby do tego pliku, do którego zapisuję tabele, zapisane zostały tylko wiersze, w których 3 komórka zawiera tekst:
has transfered (...) to your account

Pomoże mi ktoś z tym jeszcze?
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: 18.10.2025 - 08:51