Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Pobieranie danych z innej strony
Monotematyczny
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


Witam, mam problem z pobieraniem danych z innej strony

oto kod
  1. $content = file_get_contents('http://www.onet.pl/');
  2. preg_match_all('[<div class="items">(.+?)<\/div>]', $content, $wynik);
  3. print_r($wynik);
a oto błąd
  1. Array ( [0] => Array ( ) [1] => Array ( ) )


Słyszałem też że ten sposób jet dość słaby więc jak ktoś zna lepszy to bym prosił (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 13)
Turson
post
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


http://simplehtmldom.sourceforge.net/
Go to the top of the page
+Quote Post
Monotematyczny
post
Post #3





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


ok dzięki za link a można prosić o jakieś wytłumaczenie (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Szukasz diva
http://simplehtmldom.sourceforge.net/manual.htm

  1. $html = file_get_html('http://www.google.com/');
  2. $result = $html->find('div[class=items]');


Ten post edytował Turson 11.07.2014, 22:57:46
Go to the top of the page
+Quote Post
Monotematyczny
post
Post #5





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


Fatal error: Call to undefined function file_get_html() in C:\wamp\www\panels\top_news.php on line 4 coś w tej funkcji jest nie tak.
Go to the top of the page
+Quote Post
johny_s
post
Post #6





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


jak może być w niej coś nie tak skoro jej nie ma?
Go to the top of the page
+Quote Post
Monotematyczny
post
Post #7





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


  1. <?php
  2.  
  3. $results_new_news = mysql_query("SELECT id, title, text, author, date, public, img, comments FROM news WHERE public=1 ORDER BY id ASC LIMIT 3");
  4. $html = file_get_contents('http://onet.pl/');
  5. $result = $html->find('span[class=when]');
  6.  
  7. echo "<div><img src='img/21.png'></div>";
  8.  
  9. while ($new_news = mysql_fetch_array($results_new_news)) {
  10.  
  11. $text = $new_news['text'];
  12. $wstep = substr($text, 0, 275);
  13.  
  14. echo "<div style='margin-top: 2px; margin-left: 3.1px; width: 516px; height: 125px; background-image: url(img/23.png);'>
  15. <div style='float: left; padding-left: 7px; padding-top: 2px;'><img src='img/".$new_news['img']."'></div>
  16. <div style='float: left;'>
  17. <div style='width: 300px; padding-left: 5px;padding-top: 3px;'>
  18. <div><font style='font-family: Arial; font-size: 11px; color: #de6a21;'>".$result."<b>".$new_news['title']."</b></font><font style='color: #b1b1b1; font-family: Arial; font-size: 10px; margin-right: 4px; float: right;'><b>komentarzy (".$new_news['comments'].")</b></font></div>
  19. <div style='height: 73px;margin-top: 11px; margin-right: 3px;'><font style='font-family: Arial; font-size: 11px; color: #ffffff;'>".$wstep."...</font></div>
  20. <div><font style='font-family: Arial; font-size: 10px; color: #ffffff;'><b>dodał:</b></font> <font style='font-family: Arial; font-size: 10px;'><a href='#?profile=".$new_news['author']."' style='color: #de6a21;'><b>".$new_news['author']."</b></a></font> <font style='margin-left: 25px;font-family: Arial; font-size: 10px; color: #ffffff;'><b>dnia: ".$new_news['date']."</b></font> <font style='margin-left: 65px;font-family: Arial; font-size: 10px; '><a href='#?news=".$new_news['id']."' style='color: #ffffff;'><b>Więcej...</b></a></font></div>
  21. </div>
  22. </div>
  23. </div>
  24. <div style='margin-left: 5px; margin-top: 7px; margin-bottom: 7px;'><img src='img/24.png'></div>";
  25.  
  26. }
  27.  
  28. ?>
  29.  
  30.  


oraz błąd Notice: Array to string conversion in C:\wamp\www\panels\top_news.php on line 18

Ten post edytował Monotematyczny 12.07.2014, 00:14:10
Go to the top of the page
+Quote Post
johny_s
post
Post #8





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


Widocznie w $result masz tablice a nie stringa, echem tablicy nie wyświetlisz
sprawdzałeś co tam jest?
Go to the top of the page
+Quote Post
Monotematyczny
post
Post #9





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


faktycznie są tam dwa takie same elementy hmm czyli muszę teraz te zmienną w stinga zmienić ?
Go to the top of the page
+Quote Post
johny_s
post
Post #10





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


czyli musisz zdecydować co chcesz z tego wyświetlić
Go to the top of the page
+Quote Post
Monotematyczny
post
Post #11





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


w jaki sposób (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
johny_s
post
Post #12





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


ale co? nie wiesz jak wyświetlić element z tablic?
Go to the top of the page
+Quote Post
Monotematyczny
post
Post #13





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 7.08.2013

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


chyba nie bo mi coś nie wychodzi (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
johny_s
post
Post #14





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


najprościej
  1. echo $result['index'];

oczywiście index dobierasz wg. tego co masz w tej tablicy
ewentualnie
  1. echo $result[0];
  2. echo $result[1];

jeśli indeksy są numeryczne
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: 25.08.2025 - 06:40