/* ----------------------------------------------------- | The function rssToArray takes one argument: a URL | | or filename of an RSS feed in RSS 0.9x format. | | It parses the feed into an array as follows: | | array | | - item | | - [0] Headline | | - [1] Description | | - [2] Link | | - [3] Published | |___________________________________________________| | This function is (c) Dominic Smith, 2004-2005 | | Enquiries to dom@domsmith.co.uk | | Released under the General Public Licence (GPL) | | See: http://www.gnu.org/licenses/gpl.txt | ----------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ function rssToArray($rss_file) { $readrss = fopen($rss_file,r) or die("Can't open news"); $rsscont=fread($readrss,10000); //get rid of the angle brackets $rsscont=str_replace("<","<",$rsscont); $rsscont=str_replace(">",">",$rsscont); // Get image $image_start_pos=(strpos($rsscont,"<url>")+11); $image_endpos=(strpos($rsscont,"</url>")); $image_len=($image_endpos - $image_start_pos); $image_url = substr($rsscont, $image_start_pos, $image_len); // Get image link $image_link_start_pos=(strpos($rsscont,"<link>")+12); $image_link_endpos=(strpos($rsscont,"</link>")); $image_link_len=($image_link_endpos - $image_link_start_pos); $image_link = substr($rsscont, $image_link_start_pos, $image_link_len); // Get image alt text $image_alt_start_pos=(strpos($rsscont,"<description>")+19); $image_alt_endpos=(strpos($rsscont,"</description>")); $image_alt_len=($image_alt_endpos - $image_alt_start_pos); $image_alt = substr($rsscont, $image_alt_start_pos, $image_alt_len); // Get last updated date $date_start_pos=(strpos($rsscont,"<lastBuildDate>")+21); $date_endpos=(strpos($rsscont,"</lastBuildDate>")); $date_len=($date_endpos - $date_start_pos); $last_update = substr($rsscont, $date_start_pos, $date_len); // counts the number of times the item marker <item> is found $item_term="<item>"; $item_tot=substr_count($rsscont,$item_term); $item_tot=$item_tot+1; function strip_returns ($text) { return ereg_replace("(\r\n|\n|\r)", " ", $text); } $rss_file_len=99999; // strips before the first item $item_stpt=strpos($rsscont,"<item>"); $rsscont=substr($rsscont,$item_stpt,$rss_file_len); $item_stpt=0; // creates a loop to analyse each item seperately for ($item_this=1; $item_this<$item_tot; $item_this=$item_this+1) { // tells the script that the item ends after </item> $item_endpt=strpos($rsscont,"</item>"); $item_endpt=$item_endpt+13; // fetches the data for each individual item $item_cont=substr($rsscont, $item_stpt, $item_endpt); $item_cont=strip_returns($item_cont); // gets the item title $item_title_start_pos=(strpos($item_cont,"<title>")+13); $item_title_endpos=(strpos($item_cont,"</title>")); $item_title_len=($item_title_endpos - $item_title_start_pos); $item_title = substr($item_cont, $item_title_start_pos, $item_title_len); // gets the item description $item_desc_start_pos=(strpos($item_cont,"<description>")+19); $item_desc_endpos=(strpos($item_cont,"</description>")); $item_desc_len=($item_desc_endpos - $item_desc_start_pos); $item_desc = substr($item_cont,$item_desc_start_pos,$item_desc_len); // gets the item link $item_link_start_pos=(strpos($item_cont,"<link>")+12); $item_link_endpos=(strpos($item_cont,"</link>")); $item_link_len=($item_link_endpos - $item_link_start_pos); $item_link = substr($item_cont,$item_link_start_pos,$item_link_len); // gets the item Publication Date $item_udate_start_pos=(strpos($item_cont,"<pubDate>")+15); $item_udate_endpos=(strpos($item_cont,"</pubDate>")); $item_udate_len=($item_udate_endpos - $item_udate_start_pos); $item_udate = substr($item_cont,$item_udate_start_pos,$item_udate_len); // reformats item_cont $rss_array[$item_this][0] = $item_title; $rss_array[$item_this][1] = $item_desc; $rss_array[$item_this][2] = $item_link; $rss_array[$item_this][3] = $item_udate; // deletes information from the item, so the loop can restart $rsscont=substr($rsscont,$item_endpt,$rss_file_len); $item_stpt=0; $item_endpt=0; } fclose($readrss); return $rss_array; }