Добро пожаловать! Это — архивная версия форумов на «Хакер.Ru». Она работает в режиме read-only.
 

Проблема c RSS. PHP

Пользователи, просматривающие топик: none

Зашли как: Guest
Все форумы >> [Веб-программинг] >> Проблема c RSS. PHP
Имя
Сообщение << Старые топики   Новые топики >>
Проблема c RSS. PHP - 2008-11-30 17:16:25.240000   
Mamka

Сообщений: 560
Оценки: 0
Присоединился: 2007-11-26 22:20:09.313333
Нашел такой вот скриптик, который преобразовывает xml rss в html-код.
&lt;?php $RSSFEEDS = array( 0 =&gt; "http://www.site-reference.com/xml.php?c=all", 1 =&gt; "http://rss.cnn.com/rss/cnn_topstories.rss", 2 =&gt; "http://rss.slashdot.org/Slashdot/slashdot", ); // // Makes a pretty HTML page bit from the title, // description and link // function FormatRow($title, $description, $link) { return "&lt;HTML&gt; &lt;!-- RSS FEED ENTRY --&gt; &lt;p class='feed_title'&gt;$title&lt;/p&gt; &lt;p class='feed_description'&gt;$description&lt;/p&gt; &lt;a class='feed_link' href='$link' rel='nofollow' target='_blank'&gt;Read more...&lt;/a&gt; &lt;p&gt;&nbsp;&lt;/p&gt; &lt;hr size=1&gt; &lt;!-- END OF RSS FEED ENTRY --&gt; &lt;HTML&gt;"; } // we ll buffer the output ob_start(); // Now we make sure that we have a feed selected to work with if (!isset($feedid)) $feedid = 0; $rss_url = $RSSFEEDS[$feedid]; // Server friendly page cache $ttl = 60*60;// 60 secs/min for 60 minutes = 1 hour(360 secs) $cachefilename = md5($rss_url); if (file_exists($cachefilename) && (time() - $ttl &lt; filemtime($cachefilename))) { // We recently did the work, so we'll save bandwidth by not doing it again include($cachefilename); exit(); } // Now we read the feed $rss_feed = file_get_contents($rss_url); // Now we replace a few things that may cause problems later $rss_feed = str_replace("&lt;![CDATA[", "", $rss_feed); $rss_feed = str_replace("]]&gt;", "", $rss_feed); $rss_feed = str_replace("\n", "", $rss_feed); // If there is an image node remove it, we aren't going to use // it anyway and it often contains a &lt;title&gt; and &lt;link&gt; // that we don't want to match on later. $rss_feed = preg_replace('#&lt;image&gt;(.*?)&lt;/image&gt;#', '', $rss_feed, 1 ); // Now we get the nodes that we're interested in preg_match_all('#&lt;title&gt;(.*?)&lt;/title&gt;#', $rss_feed, $title, PREG_SET_ORDER); preg_match_all('#&lt;link&gt;(.*?)&lt;/link&gt;#', $rss_feed, $link, PREG_SET_ORDER); preg_match_all('#&lt;description&gt;(.*?)&lt;/description&gt;#', $rss_feed, $description, PREG_SET_ORDER); // // Now that the RSS/XML is parsed.. Lets Make HTML ! // // If there is not at least one title, then the feed was empty // it happens sometimes, so lets be prepared and do something // reasonable if(count($title) &lt;= 1) { echo "No news at present, please check back later.&lt;br&gt;&lt;br&gt;"; } else { // OK Here we go, this is the fun part // Well do up the top 3 entries from the feed for ($counter = 1; $counter &lt;= 3; $counter++ ) { // We do a reality check to make sure there is something we can show if(!empty($title[$counter][1])) { // Then we'll make a good faith effort to make the title // valid HTML $title[$counter][1] = str_replace("&", "&", $title[$counter][1]); $title[$counter][1] = str_replace("&apos;", "'", $title[$counter][1]); // The description often has encoded HTML entities in it, and // we probably don't want these, so we'll decode them $description[$counter][1] = html_entity_decode( $description[$counter][1]); // Now we make a pretty page bit from the data we retrieved from // the RSS feed. Remember the function FormatRow from the // beginning of the program ? Here we put it to use. $row = FormatRow($title[$counter][1],$description[$counter][1],$link[$counter][1]); // And now we'll output the new page bit! echo $row; } } } // Finally we'll save a copy of the pretty HTML we just created // so that we can skip most of the work next time $fp = fopen($cachefilename, 'w'); fwrite($fp, ob_get_contents()); fclose($fp); // All Finished! ob_end_flush(); // Send the output to the browser ?&gt;
вроде бы все хорошо, но есть одно НО:
допустим строка
<a class='feed_link' href='$link' rel='nofollow' target='_blank'>Read more…</a>
ссылка на источник новости. Убираю эту строку из кода и…и…ничего не меняется, ссылка остается.
или строка
for ($counter = 1; $counter <= 3; $counter++ )
которая вроде как отвечает за то, сколько будет выведено новостей из rss на страницу. Меняю 3 на 7-выводит все-равно 3 новости.

Создается впечатление, что работаю не с этим файлом(делал специально синтаксиси иррор-страница запарывалась, так что все-таки с этим).
Я что то не так понял? помогите разобраться
Post #: 1
Страниц:  [1]
Все форумы >> [Веб-программинг] >> Проблема c RSS. PHP







Связаться:
Вопросы по сайту / xakep@glc.ru

Предупреждение: использование полученных знаний в противозаконных целях преследуется по закону.