22-02-2007, 17:21
|
|
|
חבר מתאריך: 20.04.06
הודעות: 6
|
|
בעיה עם קריאת RSS
היי, אני בונה אתר כלשהו, בוא אני צריך לשלוף מרשימה ארוכה של עידכוני RSS, רק את העידכון האחרון של YNET, בגלל שהשרת אינו תומך Php 5 נאלצתי להשתמש בxml_parser ולא בפונקציה הפשוטה SimpleXML, ונתקלתי בבעיה.
אני מצליח לשלוף את כל הכתבות ללא בעיה, לאחר מכן לשלוף את הכתבות של YNET, אבל אני לא מצליח לעצור את הלולאה ברגע שאני מגיע בפעם הראשונה אל כתבה של YNET,אלא שהיא ממשיכה, עד שהיא מסיימת לשלוף את כל הכתבות של YNET.
מה אני יכול לעשות? ניסיתי break, ואפילו 3 חח.. עדיין לא עזר.
הקוד:
קוד PHP:
<?Php
class RssFeeds #### Rss Feeds from the main news sites in israel #### { function mainBoxDefault() #### The default RSS content of the main box #### { global $DB;
$RssFile = mainRssFile; $insideitem = false; $tag = ""; $title = ""; $description = ""; $link = ""; $source = "";
function startElement($parser, $name, $attrs) { global $insideitem,$tag,$title,$description,$link,$source ; if($insideitem) { $tag = $name; } elseif($name == "ITEM") { $insideitem = true; } }
function endElement($parser, $name) { global $insideitem,$tag,$title,$description,$link,$source ; if($name == "ITEM") { $sr = explode(' ',$source); $count = count($sr);
for($i = 0; $i<= $count; $i++) { if($sr[$i] == "Ynet") { print ' <div class="mainNewsBox"> <div class="title">'.$title.'</div> <div class="description">'.$description.'</div> </div>'; break; break; ///////////// 3 breaks, and still not working .. break;
} } $title = ""; $description = ""; $link = ""; $source = ""; $insideitem = false; } }
function characterData($parser, $data) { global $insideitem,$tag,$title,$description,$link,$source ; if($insideitem) { switch($tag) { case 'TITLE': $title .= $data; break; case 'DESCRIPTION': $description .= $data; break; case 'SOURCE': $source .= $data; break; case 'LINK': $link .= $data; break;
} }
}
$xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); $fp = fopen($RssFile,"r") or die("Error reading RSS data."); while($data = fread($fp,4092)) xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); fclose($fp); xml_parser_free($xml_parser); } }
$rss = new RssFeeds; switch($action) { case 'latest': $rss -> mainBoxDefault(); break; } ?>
בתודה, טל גלייכר
נערך לאחרונה ע"י WebProject בתאריך 22-02-2007 בשעה 17:25.
|