Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: sprawdzenie poprawności skryptów
Forum PHP.pl > Forum > Gotowe rozwiązania
mksdziegiel
nie wiem czemu ale nie działają co mam zmienić
plik index.php
  1. <?php
  2.  
  3. // Plik gdzie zapisac z tylko tobie znana nazwa! (daj prawa do pliku chomd o+rw plik)
  4. $filename = &#092;"pogoda4444.inc\";
  5.  
  6. // Strona z jakiej pobieramy! Uwaga wystarczy zmienic kod miasta na twoj!
  7. $site_aura = &#092;"http://pogoda.onet.pl/0,1228,38,miasto.html\";
  8.  
  9. // Jak w linii jest ten ciag wyrazow to zaczynamy szukac!
  10. $fstart = 'Teraz';
  11.  
  12. // Zapisujemy strone do tablicy $stronka
  13. $ch = curl_init();
  14. curl_setopt ($ch, CURLOPT_URL, $site_aura);
  15. curl_setopt ($ch, CURLOPT_HEADER, 0);
  16. curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
  17. $output = curl_exec($ch);
  18. if (curl_error($ch)) sru('Error: Nie moge się połaczyć ze stroną!');
  19. $stronka = explode(&#092;"n\",$output);
  20. curl_close($ch);
  21.  
  22. $znalazlem = &#092;"0\";
  23. $ile = &#092;"0\";
  24.  
  25. // Funckja do wyswietlania bledu i dodatkowo zapisuje w pliku z wynikami ciag znak
  26. w
  27. // w tym wypadku zapisze spacje (w html -> &nbsp;)
  28. function sru($blad) {
  29. if ($blad == 'Error') {
  30. if (!$plik = @fopen($filename,&#092;"w+\")) die('Nie moge zapisac w pliku z pogoda!');
  31. flock($plik,2);
  32. $zapisz = &#092;"&nbsp;\";
  33. fputs($plik,$zapisz);
  34. flock($plik,3);
  35. fclose($plik);
  36. }
  37. die(&#092;"$blad\");
  38. }
  39.  
  40. // Szukamy
  41. reset($stronka);
  42. while (list ($line_num, $line) = each ($stronka)) {
  43. if (eregi($fstart,$line)) {
  44. $znalazlem = &#092;"1\";
  45. list($a1, $a2, $a3) = split('<TABLE width=\"100%\" border=0 cellspacing=0 cellpadding=0>', $line);
  46. // SZUKAMY W LINII - PROGNOZY
  47. if (!eregi(&#092;"bottom><IMG src=0 height=4><BR>(Wieczorem|Nad ranem|Przed południem|Po południu)<BR>([0-9]{2})-([0-9]{2})<BR><IMG(.+)align=\"absmiddle\"> ([0-9]{1,3}) km/h <IMG(.+)nowrap>([0-9]{1,2})/([0-9]{1,2}) &deg(.+)nieg:</TD><TD class=a1b>([0-9]{1,2}).([0-9]{1,2}) mm(.+)nowrap>([0-9]{1,5}) hPa(.+)class=a1b>([0-9]{1,2}).([0-9]{1,2}) mm\", $a2, $dane)) sru('Error');
  48.  
  49. // Pora dnia - (Rano/Popoludniu/Wieczorem)
  50. $dane_a[1] = htmlspecialchars($dane[1]);
  51. // Pogoda w godzinach 2-3
  52. $dane_a[2] = htmlspecialchars($dane[2]);
  53. $dane_a[3] = htmlspecialchars($dane[3]);
  54. // Nie potrzebne
  55. $dane_a[4] = htmlspecialchars($dane[4]);
  56. // Wiatr km/h
  57. $dane_a[5] = htmlspecialchars($dane[5]);
  58. // Nie potrzebne
  59. $dane_a[6] = htmlspecialchars($dane[6]);
  60. // Temp. min 7 max. 8
  61. $dane_a[7] = htmlspecialchars($dane[7]);
  62. $dane_a[8] = htmlspecialchars($dane[8]);
  63. // Nie potrzebne
  64. $dane_a[9] = htmlspecialchars($dane[9]);
  65. // Snieg 10.11 mm
  66. $dane_a[10] = htmlspecialchars($dane[10]);
  67. $dane_a[11] = htmlspecialchars($dane[11]);
  68. // Nie potrzebne
  69. $dane_a[12] = htmlspecialchars($dane[12]);
  70. // Cisnienie w hpa
  71. $dane_a[13] = htmlspecialchars($dane[13]);
  72. // Nie potrzebne
  73. $dane_a[14] = htmlspecialchars($dane[14]);
  74. // Deszcz 15.16 mm
  75. $dane_a[15] = htmlspecialchars($dane[15]);
  76. $dane_a[16] = htmlspecialchars($dane[16]);
  77.  
  78. if (!eregi(&#092;"bottom><IMG src=0 height=4><BR>(Wieczorem|Nad ranem|Przed południem|Po południu)<BR>([0-9]{2})-([0-9]{2})<BR><IMG(.+)align=\"absmiddle\"> ([0-9]{1,3}) km/h <IMG(.+)nowrap>([0-9]{1,2})/([0-9]{1,2}) &deg(.+)nieg:</TD><TD class=a1b>([0-9]{1,2}).([0-9]{1,2}) mm(.+)nowrap>([0-9]{1,5}) hPa(.+)class=a1b>([0-9]{1,2}).([0-9]{1,2}) mm\", $a3, $dane)) sru('Error');
  79.  
  80. // Pora dnia - (Rano/Popoludniu/Wieczorem)
  81. $dane_b[1] = htmlspecialchars($dane[1]);
  82. // Pogoda w godzinach 2-3
  83. $dane_b[2] = htmlspecialchars($dane[2]);
  84. $dane_b[3] = htmlspecialchars($dane[3]);
  85. // Nie potrzebne
  86. $dane_b[4] = htmlspecialchars($dane[4]);
  87. // Wiatr km/h
  88. $dane_b[5] = htmlspecialchars($dane[5]);
  89. // Nie potrzebne
  90. $dane_b[6] = htmlspecialchars($dane[6]);
  91. // Temp. min 7 max. 8
  92. $dane_b[7] = htmlspecialchars($dane[7]);
  93. $dane_b[8] = htmlspecialchars($dane[8]);
  94. // Nie potrzebne
  95. $dane_b[9] = htmlspecialchars($dane[9]);
  96. // Snieg 10.11 mm
  97. $dane_b[10] = htmlspecialchars($dane[10]);
  98. $dane_b[11] = htmlspecialchars($dane[11]);
  99. // Nie potrzebne
  100. $dane_b[12] = htmlspecialchars($dane[12]);
  101. // Cisnienie w hpa
  102. $dane_b[13] = htmlspecialchars($dane[13]);
  103. // Nie potrzebne
  104. $dane_b[14] = htmlspecialchars($dane[14]);
  105. // Deszcz 15.16 mm
  106. $dane_b[15] = htmlspecialchars($dane[15]);
  107. $dane_b[16] = htmlspecialchars($dane[16]);
  108.  
  109. // zapisujemy wynik w pliku z pogoda!
  110. if (!$plik = @fopen($filename,&#092;"w+\")) die('Nie moge zapisac w pliku z pogoda!');
  111. flock($plik,2);
  112.  
  113. $zapisz = <<< EOT
  114. <font color=\"blue\">Pogoda dla Zgorzelca:</font> Teraz &nbsp;(w godz.$dane_a[2]-$dane_a[3])&nbsp;&nbsp;temp.min./max.: $dane_a[7]/$dane_a[8] &deg;C, ciśnienie: $dane_a[13] hPa, wiatr: $dane_a[5] km/h, deszcz: $dane_a[15].$dane_a[16] mm, śnieg: $dane_a[10].$dane_a[11] mm,&nbsp;&nbsp;&nbsp;Później &nbsp;(w godz.$dane_b[2]-$dane_b[3])&nbsp;&nbsp;temp.min./max.: $dane_b[7]/$dane_b[8] &deg;C, ciśnienie: $dane_b[13] hPa, wiatr: $dane_b[5] km/h, deszcz: $dane_b[15].$dane_b[16] mm, śnieg: $dane_b[10].$dane_b[11] mm&nbsp;&nbsp;&nbsp;
  115. EOT;fputs($plik,$zapisz);
  116. flock($plik,3);
  117. fclose($plik);
  118.  
  119. }
  120. }
  121. if ($znalazlem == \"0\") sru('Error: Nie znalazłem wyników na stronie - możliwa zmiana kodu strony z pogodą!');
  122. ?>

plik check.php
  1. <?php
  2. // Stronka
  3. $site_aura = &#092;"http://pogoda.onet.pl/0,1228,38,miasto.html\";
  4.  
  5. $ch = curl_init();
  6. curl_setopt ($ch, CURLOPT_URL, $site_aura);
  7. curl_setopt ($ch, CURLOPT_HEADER, 0);
  8. curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
  9. $output = curl_exec($ch);
  10. if (curl_error($ch)) die(&#092;"Nie moge otowrzyc strony $site_aura\");
  11. $stronka = explode(&#092;"n\",$output);
  12. curl_close($ch);
  13.  
  14. reset($stronka);
  15. while (list ($line_num, $line) = each ($stronka)) {
  16.  
  17. echo &#092;"<b>Linia $line_num:</b> \", htmlspecialchars ($line), \"<br>n\";
  18. }
  19. ?>



i jeszcze drugi skrypt
  1. <?
  2.  
  3.  
  4. function unhtmlspecialchars( $string ) {
  5.  $string = str_replace ( '&amp;', '&', $string );
  6.  $string = str_replace ( ''', ''', $string );
  7.  $string = str_replace ( '&quot;', '\"', $string );
  8.  $string = str_replace ( '&lt;', '<', $string );
  9.  $string = str_replace ( '&gt;', '>', $string );
  10.  return $string;
  11. }
  12.  
  13.  
  14.  
  15. $linki['gazeta']  = 'http://www.gazeta.pl/pub/rss/sport.xml';
  16. $linki['chip']  = 'http://www.chip.pl/rss/arts.rss';
  17. $linki['webinside'] = 'http://www.webinside.pl/rss.php';
  18. $linki['mks_vir'] = 'http://www.mks.com.pl/rss/index.rss';
  19. $linki['4programmers.net-forum'] = 'http://4programmers.net/rss.php?rss=topic';
  20. $linki['dziennik internauty'] = 'http://di.com.pl/rss/di.rss';
  21. $linki['e-gospodarka']  = 'http://news.egospodarka.pl/rss.thtml?cat=127';
  22. $linki['linux.pl']  = 'http://www.linux.pl/rss.php';
  23. $linki['informator m. Łomża'] = 'http://www.lomza.info/backend.php';
  24.  
  25. $strona = (!empty($_POST['rss_canal'])) ? $_POST['rss_canal'] : 'dziennik internauty';
  26.  
  27. $rss_link = (array_key_exists($strona,$linki)) ? $linki[$strona] : $linki['dziennik internauty'];
  28.  
  29. $separator = '|~|';
  30. $item = false;
  31. $chanel_title = '';
  32. $encoding = '';
  33. $lines_item = '';
  34. $items_tab = array();
  35.  
  36. $rss_link = parse_url($rss_link);
  37.  
  38. $header = &#092;"GET \".$rss_link[\"path\"].(isset($rss_link[\"query\"]) ? \"?\".$rss_link[\"query\"] : false).\" HTTP/1.0rn\";
  39. $header .= &#092;"Host: \".$rss_link['host'].\"rn\";
  40. $header .= &#092;"Content-type: application/x-www-form-urlencodedrn\";
  41. $header .= &#092;"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; www.rss4all.net)rn\";
  42. $header .= &#092;"Content-length: \" . strlen($request) . \"rnrn\";
  43.  
  44. if ($rss_read = @fsockopen($rss_link['host'], 80, $err_num, $err_msg, 15)) {
  45.  
  46. fputs($rss_read, $header . $request);
  47.  
  48. while (!feof($rss_read)) {
  49.  
  50.  
  51.  $line = trim(fgets($rss_read,10000));
  52.  
  53. if (preg_match(&#092;"#<?xml.+(|encoding=\"([w-]+)\").*questionmark.gif>#i\",$line,$enc)) // nagłówek XML i pobieranie
  54.  $encoding = preg_replace(\"#<?xml.+encoding=&#092;"([w-]+)\".*?>#s\",\"1\",$enc[0]); // kodowania tekstu
  55.  
  56.  
  57. if (!empty($encoding)) {
  58.  
  59. if (!$item) $chanel_title .= $line;
  60.  
  61. if ((preg_match(\"#<item(| .+?)>#\",$line)) && (!$item)) {
  62.  $item = true;
  63.  $chanel_title = preg_replace(\"#<image.*|<item.*#\",\"\",$chanel_title);
  64.  $chanel_title = preg_replace(\"#.*<title(|.+?)>(.*?)</title>.*#\",\"2\",$chanel_title);
  65. }
  66.  
  67. }
  68.  
  69. if ($item) $lines_item .= $line;
  70.  
  71. }
  72.  
  73. fclose($rss_read);
  74.  
  75. if (preg_match_all(\"#<item(| .+?)>.+?</item>#\",$lines_item,$lines_item)) {
  76.  
  77. foreach ($lines_item[0] as $wart) {
  78.  
  79. preg_match(\"#<link>.+?</link>#\",$wart,$link);
  80. $link = preg_replace(\"#<link>(.+?)</link>#\",\"1\",$link[0]);
  81.  
  82. if (preg_match(\"#<title(| .+?)>.+?</title>#\",$wart,$title)) {
  83.  $title = preg_replace(\"#<title(| .+?)>(.+?)</title>#\",\"2\",$title[0]);
  84.  $link = '<a href=\"'.$link.'\" target=_blank>'.$title.'</a>';
  85. } else $link = '<a href=\"'.$link.'\" target=_blank>'.$link.'</a>';
  86.  
  87. if (preg_match(\"#<description>.+?</description>#\",$wart,$description)) {
  88.  $description = preg_replace(\"#<description>(.+?)</description>#\",\"1\",$description[0]);
  89.  $description = str_replace(array(\"<![CDATA[\",\"]]>\"),\"\",$description);
  90.  $description = preg_replace(\"#<a href=(.+?)>#i\",\"<a href=1 target=_blank>\",$description);
  91. } else $description = '';
  92.  
  93. if (!empty($link)) {
  94.  $items_tab[] = $description.$separator.$link;
  95. }
  96.  
  97. }
  98.  
  99. }
  100.  
  101. unset($lines_item,$line);
  102.  
  103. } else Die(\"błąd otwarcia kanału RSS: $rss_link\");
  104. ?>
  105. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
  106. <HTML>
  107. <HEAD>
  108. <META NAME=\"GENERATOR\" Content=\"Microsoft Visual Studio 6.0\">
  109. <META http-equiv=Content-Type content=\"text/html; charset=ISO-8859-2\">
  110. <TITLE>RSS reader by Twardy</TITLE>
  111. <STYLE type=\"text/css\">
  112. body {
  113. font-family: Verdana, Arial, Helvetica, sans-serif;
  114. font-size: 11px;
  115. COLOR: #333;
  116. }
  117. a { color:#006486; }
  118. a:hover { color:#1d93b6; }
  119. input,select {
  120. font-family: Verdana, Arial, Helvetica, sans-serif;
  121. font-size: 11px;
  122. border-style: solid; border-color: Gray; border-width: 1px;
  123. height: 17px;
  124. }
  125. </STYLE>
  126. </HEAD>
  127. <BODY>
  128. <form action=\"<? echo $_SERVER['PHP_SELF']; ?>\" method=POST id=form1 name=form1>
  129. <select id=rss_canal name=rss_canal>
  130. <?
  131. foreach ($linki as $klucz => $wart) {
  132.  
  133. echo &#092;"<option\";
  134. if ($strona == $klucz) echo ' selected=\"selected\"';
  135. echo&#092;">$klucz</option>rn\";
  136.  
  137. }
  138. ?>
  139. </select>&nbsp;<INPUT type=\"submit\" value=\"pokaż\" name=pokaz>
  140. </form>
  141. <?
  142. if (count($items_tab) > 0) {
  143. echo &#092;"<b>$chanel_title</b><br>kodowanie: $encoding<br><br><br>nnn\";
  144.  
  145. foreach ($items_tab as $wart) {
  146.  list($description,$link) = explode($separator,$wart);
  147. echo &#092;"$link<br><br>nn\";
  148. if (!empty($description)) echo stripslashes(unhtmlspecialchars($description)).&#092;"<br><br><br>nnn\";
  149. }
  150. }
  151. ?>
  152. </BODY>
  153. </HTML>

pozdrawiam
Michał2000
napisz czego oczekujesz i co niedziała
mksdziegiel
no wyskakuja błędy
mike
Uwzglądniając Twój opis błądów.
I ich sam wygląd ( z przytoczonego kodu ).
Jestem w stanie stwierdzić, że skrypt nie działa, bo :
Zupa za słona

Jeżeli chcesz żeby ktoś się wysilił odpowiadając Ci, to wysil się i przedstaw problem ( nie tylko pliki ).
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.