[ mordor @ 27.08.2004. 10:40 ] @
Za citanje xml feed-a koristim klasu koju sam preuzeo sa phpclasses i malo je modifikovao shodno mojim potrebama. Ona odlicno radi osim za URI tag... XML: http://www.searchfeed.com/rd/f...589&cat=warhammer&nl=5 PHP KLASA: Code: <?php class feedReader1{ var $feedReader1; // parser var $feedUrl1; // url do ficheiro xml/rss var $node1; // número de nós dos items var $channelFlag1; // flag var $currentTag1; // actual tag var $outputData1; // array dos dados (notícias formatadas) var $itemFlag1; // flag var $imageFlag1; // flag function feedReader1(){ //constructor iniciação dos valores por defeitos dos elementos da classe $this->feedReader1=""; $this->feedUrl1=""; $this->node1=0; $this->channelFlag1=false; $this->currentTag1=""; $this->outputData1=array(); $this->itemFlag1=false; $this->imageFlag1=false; } function setfeedUrl1($url){ //indicamos o endereço do ficheiro xml/rss $this->feedUrl1=$url; } function getfeedoutputdata1(){ //retornamos o array com as notícias formatadas return $this->outputData1; } function getFeedNumberOfNodes1(){ //retornamos o número de notícias return $this->node1; } function parseFeed1(){ $this->feedReader1=xml_parser_create(); xml_set_object($this->feedReader1,&$this); xml_parser_set_option($this->feedReader1,XML_OPTION_CASE_FOLDING,true); xml_set_element_handler($this->feedReader1,"openTag","closeTag"); xml_set_character_data_handler($this->feedReader1,"dataHandling"); if(!($fp=@fopen($this->feedUrl1,"r"))){ $errorDefinition="Não foi possível encontrar o ficheiro pretendido."; echo $errorDefinition; } while($data=@fread($fp,4096)){ if(!@xml_parse($this->feedReader1,$data,feof($fp))){ $errorDefinition=xml_error_string(xml_get_error_code($this->feedReader1)); echo $errorDefinition; } } xml_parser_free($this->feedReader1); } function openTag($parser,$name,$attrs){ if($name){ switch(strtolower($name)){ case "listing":$this->channelFlag1=false;$this->imageFlag1=false;$this->itemFlag1=true;$this->node1++;break; default:$this->currentTag1=strtolower($name);break; } } } function closeTag($parser,$name){ $this->currentTag1=""; } function dataHandling($parser,$data){ if($this->itemFlag1){ switch($this->currentTag1){ case "title":$this->outputData1["listing"][$this->currentTag1][$this->node1-1]=$data;break; case "uri":$this->outputData1["listing"][$this->currentTag1][$this->node1-1]=$data;break; case "url":$this->outputData1["listing"][$this->currentTag1][$this->node1-1]=$data;break; case "description":$this->outputData1["listing"][$this->currentTag1][$this->node1-1]=$data;break; case "bid":$this->outputData1["listing"][$this->currentTag1][$this->node1-1]=$data;break; } } } } ?> Array dobijam: Code: <?php include("inc/serch_feed_xml.php"); $ob=new feedReader1(); $ob->setFeedUrl1("http://www.searchfeed.com/rd/f...cat=warhammer&nl=5&ip=".$_SERVER['REMOTE_ADDR'].""); $ob->parseFeed1(); $array=$ob->getFeedOutputData1(); $number=$ob->getFeedNumberOfNodes1(); for($i=0;$i<$number;$i++){ echo "<div class=\"poster\" style=\"margin-bottom: 2px;\"><font size='1'><strong>›</strong></font> <a class=\"head\" href='" . $array["listing"]["uri"][$i] . "'>" . $array["listing"]["title"][$i] . " - </a>".$array["listing"]["bid"][$i]."</div>"; } ?> Dakle sve tagove vidi kako treba ali URI ne ... izbacuje samo zadnju varijablu iz url-a odnosno &ex=[neki broj] Kako ovo da sredim , u cemu je problem? |