Warnung: file_put_contents(/home/www/web1/html/php_dev/test.txt) [function.file-put-contents]: failed to open stream: Permission denied in /home/www/web1/html/php_dev/sys/lib.activity.php (Zeile 58)
RSS Feed (dringend) [Archiv] - PHP-Scripte PHP-Tutorials PHP-Jobs und vieles mehr
ebiz-webhosting
- Ad -
php-resource




Archiv verlassen und diese Seite im Standarddesign anzeigen :
RSS Feed (dringend)


 
uschi
09-10-2004, 18:33 
 
Hallo, muss bis morgen früh folgendes geschafft haben->

Ich muss von http://www.nytimes.com/services/xml/rss/nyt/Arts.xml die image attribute auslesen, also das diese in einem array habe:

Array
(
=>
[TITLE] =>
[LINK] =>
)


meine funktion beim characterHandler:

function characterData($parser, $data)
{
global $node, $item_now, $image_struct;

if($node == "image")
{
echo "item: ".$item_now." + value: ".$data."<br>";

switch($item_now){
case "url": $image_struct["URL"] = $data; break;
case "title": $image_struct["TITLE"] = $data; break;
case "LINK": $image_struct["LINK"] = $data; break;
}
}
}


aber das ist die ausgabe:

Ausgabe:
item: IMAGE + value:
item: IMAGE + value:
item: URL + value: [url]http://www.nytimes.com/images/section/NytSectionHeader.gif?partner=rssnyt
item: URL + value:
item: URL + value:
item: TITLE + value: The New York Times
item: TITLE + value: >
item: TITLE + value: Arts
item: TITLE + value:
item: TITLE + value:
item: LINK + value: http://www.nytimes.com/pages/arts/index.html
item: LINK + value:
item: LINK + value:


wahrscheinlich eine problem mit: ">" im titel.

was tun?

 
TobiaZ
10-10-2004, 00:47 
 
(dringend) http://learn.to/cooldown

 
pekka
10-10-2004, 01:52 
 
Ich hab wenig Ahnung von RSS und bin schwer angeheitert... Falls Du aber noch Hilfe brauchst, poste aber mal die Parserfunktionen und vor allem, wie die Ausgabe aussehen soll (Blicke das Problem nicht ganz).

 
Samson2k
10-10-2004, 10:14 
 
Ich habe mir einen Parser gebastelt, allerdings hat der noch nicht alles was ich will und brauche, aber er funktioniert :D

<?php
// RSS-Parser Class for parsing RSS-Newsfeeds with Expat
// Copyright by Christian Koepp 2004
// http://www.koepp-online.com
// Published unter the terms of the GNU License

// for more information about RSS check this websites:
// http://blogs.law.harvard.edu/tech/stories/storyReader$15
// http://blogs.law.harvard.edu/tech/rss


class rss_parser {
var $rss = array();
var $i = -1;
var $cache;
var $top;

function rss_parser() {

$this->parser = xml_parser_create();

xml_set_object($this->parser, $this);
}

// set main elements
function start_element($parser,$name,$attr) {

$this->cache = strtoupper($name);

if($this->cache == "CHANNEL" || $this->cache == "ITEM" || $this->cache == "IMAGE") {
$this->top = $name;

if($this->cache == "ITEM")
$this->i++;
}
}


// close sub- and main-element
function end_element($parser,$name) {

$this->cache = NULL;

if($this->top == $name)
$this->top = NULL;
}

// take contents in array
function cdata($parser,$content) {

if(strlen(trim($content)) > 1 && $this->cache != NULL) {

if($this->top == "CHANNEL") {
($cache != "LINK") ?
$this->rss[$this->top][$this->cache] = htmlentities($content) :
$this->rss[$this->top][$this->cache] = $content;
}

if($this->top == "ITEM") {
($cache != "LINK") ?
$this->rss[$this->top][$this->i][$this->cache] = htmlentities($content) :
$this->rss[$this->top][$this->i][$this->cache] = $content;
}

if($this->top == "IMAGE") {
($cache != "LINK" && $cache != "URL") ?
$this->rss[$this->top][$this->cache] = htmlentities($content) :
$this->rss[$this->top][$this->cache] = $content;
}
}
}

function parse($file) {

$xml = file("$file");

xml_set_element_handler($this->parser,"start_element","end_element");

xml_set_character_data_handler($this->parser,"cdata");

foreach($xml as $elem)
xml_parse($this->parser, $elem);

xml_parser_free($this->parser);
}
}

?>

Aufrufen tust du ihn so:
$rss = new rss_parser;
$rss->parse("URL");
print_r($rss->rss);

Wie gesagt bisher kann die Klasse noch nichts außer ein array ausgeben...


Alle Zeitangaben in WEZ +2. Es ist jetzt 19:32 Uhr.