![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 34 Pomógł: 0 Dołączył: 16.12.2006 Ostrzeżenie: (0%) ![]() ![]() |
Witam, mam problem: mam stronkę prostą z podpiętym RSS Fetch dzięki któremu odbieram wiadomości z innych serwisów, wszystko działa ale w pobieranych wiadomościach nie mam polskich znaków. Zamiast np. ą ę ś mam pytajniki (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Poniżej kod dokumentu/mojej stronki, natomiast rss_fetch to oddzielny plik. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <TITLE>XXXX </TITLE> <META name="description" content="XXXXX "> <META name="keywords" content="XXXXX"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Language" content="pl"> <META name="rating" content="General"> <META name="ROBOTS" content="index,follow"> <META name="REVISIT-AFTER" content="7 days"> <META name="ROBOTS" content="ALL"> <style type="text/css"><!-- h3 { text-align: justify; font: italic normal 12pt georgia; letter-spacing: 1px; margin-bottom: 0px; color: #555753; margin: 0px; padding: 0px; } h2 { font: italic normal 14pt georgia; letter-spacing: 1px; margin-bottom: 0px; color: #A3A697; } body {font: normal 10pt georgia; color: #000000; margin: 0px; padding: 0px; } p { margin: 0px; padding: 0px; } h1 { font: italic normal 28pt Trebuchet MS; letter-spacing: 1px; margin-bottom: 0px; color: #051829; } a:link { font: normal 12pt ; text-decoration: none; color: #051829; } a:visited { text-decoration: none; color: #051829; } a:hover, a:active { text-decoration: underline; color: #800000; } --> </style> </head> <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" link="#03223B" vlink="#003399" alink="#800000"> <table border="0" width="100%" style="background-repeat: repeat-x; background-position: center bottom" height="270"> <tr> <td align="center" valign="bottom" style="background-image: url('../topbg.jpg'); background-repeat: repeat-x; background-position: center bottom"> <p align="center"> <img border="0" src="xxxx" width="760" height="241"></td> </tr> </table> <table border="0" width="100%" height="71"> <tr> <td> <p align="center"></td> </tr> </table> <div align="center"> <p align="center"><font size="5">xxxxx</font></p> <p align="center"> </p> <table border="0" width="734"> <tr> <td width="188" align="left" valign="top"> <ul> <li> <a class="m" href="austria"><font size="4">xxx</font></a><font size="4"> </font> </li> <li> <a class="m" href="belgia"><font size="4">xxxx</font></a><font size="4"> </font> </li> <li> <a class="m" href="dania"><font size="4">xxxx</font></a></li> <li> </ul> <p> <img border="0" src="xxxx" align="right"></p> <p> </td> <td width="397" align="left" valign="top"> <p align="center"></p> <table cellpadding="2" cellspacing="1" width="100%" align="center"> <tr> <td width="100%" align="center" bgcolor="#d4d6d5"> <font size="5">xxxxx</font></td> </tr> <?php include_once "./rss_fetch.php"; $html = " <tr>\n"; $html .= " <td >\n"; $html .= " <font size='+1'><a href='#{link}' target='_new'>#{title}</a></font><br />\n"; $html .= " #{description}<br />\n"; $html .= " <font >#{pubDate}<br /><br />\n"; $html .= " </td>\n"; $html .= " </tr>\n"; $rss = new rss_parser("http://rss.gazeta.pl/pub/rss/praca.xml", 10, $html, 1); ?> </table> </td> <td width="135" align="left" valign="top"></td> </tr> </table> </div> <table border="0" width="100%" bgcolor="#03223B"> <tr> <td> </td> </tr> </table> </body> </html> Ten post edytował Ferago 16.12.2007, 16:07:03 |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 19 Pomógł: 0 Dołączył: 6.06.2007 Skąd: Bydgoszcz Ostrzeżenie: (0%) ![]() ![]() |
To dlatego, że Twoja strona jest w UTF8 a RSS idzie w ISO 8859-2. Przekonwertuj.
|
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 34 Pomógł: 0 Dołączył: 16.12.2006 Ostrzeżenie: (0%) ![]() ![]() |
To dlatego, że Twoja strona jest w UTF8 a RSS idzie w ISO 8859-2. Przekonwertuj. Działa,najlepsze jest to że dzisiaj już tak robiłem, nie wiem dlaczego nie zauważyłem że działało, chyba muszę zacząć się wysypiać, dzięki. Ten post edytował Ferago 17.12.2007, 01:14:51 |
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 4 Pomógł: 0 Dołączył: 21.06.2009 Ostrzeżenie: (0%) ![]() ![]() |
Witajcie,
Przepraszam, że odkopuję temat ale mam identyczny problem jak kolega powyżej. Próbowałem kombinować z przekonwertowaniem za pomocą funkcji: Kod mb_convert_encoding($zmienna, "ISO-8859-2", "UTF-8"); Niestety bez skutków. Jako, że z php jestem ostro początkujący byłbym bardzo wdzięczny jeśli ktoś by mi powiedział gdzie co powinienem wstawić aby UTF8 zmienił się w ISO. Z góry dziękuję. |
|
|
![]()
Post
#5
|
|
Grupa: Zarejestrowani Postów: 1 135 Pomógł: 158 Dołączył: 19.03.2009 Skąd: Toruń Ostrzeżenie: (0%) ![]() ![]() |
Witajcie, Przepraszam, że odkopuję temat ale mam identyczny problem jak kolega powyżej. Próbowałem kombinować z przekonwertowaniem za pomocą funkcji: Kod mb_convert_encoding($zmienna, "ISO-8859-2", "UTF-8"); Niestety bez skutków. Jako, że z php jestem ostro początkujący byłbym bardzo wdzięczny jeśli ktoś by mi powiedział gdzie co powinienem wstawić aby UTF8 zmienił się w ISO. Z góry dziękuję. Przekonwertuj programem Grzegrzółką Nie przepraszaj dobrze zrobiłeś niż bez sensu zakładać kolejny temat . Ten post edytował krzysztof_kf 15.07.2010, 15:20:10 |
|
|
![]()
Post
#6
|
|
Grupa: Zarejestrowani Postów: 4 Pomógł: 0 Dołączył: 21.06.2009 Ostrzeżenie: (0%) ![]() ![]() |
Tylko, że Gżegżółka nie rozwiąże chyba moich problemów. Z tego co widzę to jest to wyłącznie program zmieniający znaki ale bardziej przydatny przy konwertowaniu jednorazowym (przenosiny baz mysql, tłumaczenie plików tekstowych itd.).
Mam kanał RSS, z którego pobieram dane - http://www.grasz.org/forum/index.php?/rss/...sc-left-4-dead/ A to strona, na której owe dane są zamieszczane - http://www.left4dead.org.pl/ Jak widać są krzaki ale wystarczy w przeglądarce zmienić wyświetlanie na UTF8 i krzaki wyświetlają się prawidłowo. Zatem potrzeba, w którymś miejscu skryptu wstawić komendę gdzie opis i tytuł są w locie zmieniane na ISO. Na pewno się da, tylko nie wiem gdzie to dać i z jakimi parametrami. Oto kod skrypty pobierającego dane z RSS: Kod <?php class rss_parser { var $update_interval = 10; /* How often to fetch the rss file A cached version will be used between updates */ var $data_directory = "/var/www/vhosts/left4dead.org.pl/httpdocs/zas"; /* Where to store the rss data from the feeds Note: an absolute path is better than a relative path here unless you plan on keeping the script to display the feeds in the same folder as this file and the feeds. */ /* NO NEED TO EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING */ var $rss_url; var $num_to_show; var $do_update; var $tags = array(); var $content; var $rss = array(); var $feed_title; var $feed_link; var $feed_description; var $my_html; function rss_parser($url, $numtoshow = 10, $html = "", $update = 0) { $this->rss_url = $url; $this->num_to_show = $numtoshow; $this->do_update = $update; $this->my_html = preg_replace("/(#{.*?):(.*?})/", "\\1__\\2", $html); //xx:xx tag workaround $this->content = $this->fetch_feed(); $this->parse_feed(); $this->show(); } /* string */ function fetch_feed() { $url_parts = parse_url($this->rss_url); $filename = $url_parts['host'] . str_replace("/", ",", $url_parts['path']) . "_" . @$url_parts['query']; if(file_exists($this->data_directory . "/$filename")) { $last = filemtime($this->data_directory . "/$filename"); if(time() - $last > $this->update_interval * 60 || $this->update_interval == 0) { $update = 1; } } else { $create= 1; } if($create == 1 || ($this->do_update == TRUE && $update == 1)) { $fp = @fsockopen($url_parts['host'], 80, $errno, $errstr, 5); if (!$fp) { echo "Couldn't open rss feed {$this->feed_url} in {$_SERVER['PHP_SELF']}<br />\n"; return; } fputs($fp, "GET " . $url_parts['path'] . "?" . @$url_parts['query'] . " HTTP/1.0\r\n" ."Host: " . $url_parts['host'] . "\r\n" ."User-Agent: Drew's RSS Reader 0.1\r\n" ."Connection: Close\r\n\r\n"); while(!feof($fp)) { $rss_data .= @fgets($fp, 1024); } list(, $rss_data) = explode("\r\n\r\n", $rss_data, 2); $output = @fopen($this->data_directory . "/$filename", "w+"); if(!$output) { return $rss_data; } else { flock($output, LOCK_EX); fputs($output, $rss_data); flock($output, LOCK_UN); fclose($output); } } //update return file_get_contents($this->data_directory . "/$filename"); } /* void */ function parse_feed() { preg_match("/<title>(.*?)<\/title>/", $this->content, $title); $this->feed_title = @$title[1]; preg_match("/<link>(.*?)<\/link>/", $this->content, $link); $this->feed_link = @$link[1]; preg_match("/<description>(.*?)<\/description>/", $this->content, $description); $this->feed_description = @$description[1]; mb_convert_encoding($description[1], "ISO-8859-2", "UTF-8"); preg_match_all("/<item[^>]*>(.*?)<\/item>/s", $this->content, $items); if (sizeof($items[0]) == 0) { echo "No item elements found in rss feed.<br />\n"; } for($i = 0; $i < sizeof($items[0]); ++$i) { preg_match_all("/(?:<([\w:]*)[^>]*>(?:<!\[CDATA\[)?(.*?)(?:]]>)?<\/\\1>)+?/si", preg_replace("/<item[^>]*>/", "", $items[0][$i]), $elements); for($j = 0; $j < sizeof($elements[0]); ++$j) { $elements[1][$j] = str_replace(":", "__", $elements[1][$j]); //regex fix for items with : like dc:date $this->rss[$i][$elements[1][$j]] = trim(html_entity_decode($elements[2][$j])); } } } /* void */ function show() { if($this->my_html == "") { $this->show_html(); } else { $this->show_user_html(); } } function show_html() { $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss)); for($i = 0; $i < $show; ++$i) { echo "- <a href=\"{$this->rss[$i]['link']}\" target=\"_new\">{$this->rss[$i]['title']}</a><br />\n"; } } function show_user_html() { $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss)); for($i = 0; $i < $show; ++$i) { extract($this->rss[$i]); $item = preg_replace("/#\{([^}]+)}/e", "$\\1", $this->my_html); echo $item; } } } // end class ?> A to kod wyświetlający Kod <?php
include_once "./zas/rss_fetch.php"; $html = " <div><table cellpadding='0' cellspacing='0' align='center' width='600'><tr> <td style='background:url(../images/newsa.gif); height: 50px; width: 600px; background-repeat: no-repeat;'>\n"; $html .= " <div style='font-size: 13px; color: #E6E6E6; margin-left: 8px; margin-top: 5px;'><a href='#{link}' ><b>#{title}</b></a></div>\n"; $html .= " <div style='font-size: 10px; color: #E6E6E6; margin-left: 8px; margin-top: 5px;'> Opublikowano: #{pubDate}</div></td></tr>"; $html .= " <tr><td><div style='font-size: 11px; color: #CBCBCB; margin-left: 4px; margin-top: 5px; margin-bottom: 10px; text-align:justify;'> #{description}</div></td></tr></table></div><br>\n"; $rss = new rss_parser("http://www.grasz.org/forum/index.php?/rss/forums/2-spolecznosc-left-4-dead/", 5, $html, 1); ?> Ten post edytował neoXs 15.07.2010, 15:31:26 |
|
|
![]() ![]() |
![]() |
Aktualny czas: 22.08.2025 - 21:23 |