RSS Script

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Lasse

Lasse

22/01/2007 15:04:00
Quote Anchor link
Hallo iedereen,

K had een vraagje. Om op mijn website een RSS feed weer te geven gebruik ik onderstaand script. Alleen ik vroeg mij af hoe ik erover kan zorgen dat wanneer je op de link klikt(die de RSS feed voorziet), deze in een nieuw scherm opent, oftewel blank.

Alvast bedankt!

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?
/*
##############################################################################
RSS parser
by Tri Pham ([email protected])
http://www.tripham.nl/

Very simple and basic yet powerful!
Works for standard RSS version 0.91, 1.0 and 2.0
You are free to use this script, as long you remember who made this :-)
##############################################################################
*/

// Error definitions

define(OPEN,"Error: opening RSS file");
define(PARSE,"Error: parsing RSS file");

// URL RSS file
// Fill in the RSS URL

$rss_file = "http://url.com/example.rss";

// Class with all the <item> and <channel> variables which will hold the information
// and parsing functions

class rss_parser {
    // Flag tells which tag we enter
    var $flag = 0;
    var
$tag = "";
    
    // <item> information
    var $title = "";
    var
$description = "";
    var
$link = "";
    var
$pubdate = "";
    // </item>

    // <channel> information

    var $channel_copyright = "";
    var
$channel_managingeditor = "";
    var
$channel_language = "";
    var
$channel_lastbuilddate = "";
    // </channel>


// Function for start tag such as <item> and <channel>

function startElement($parser, $tagname, $attributess) {
    $this->tag = $tagname;
    if($this->tag == "CHANNEL") $this->flag = 1;
    elseif($this->tag == "ITEM") $this->flag = 2;
    elseif($this->tag == "IMAGE") $this->flag = 3; // Dummy since we dont use it
}

// Function for end tag such as </item> and </channel>
function endElement($parser, $tagname) {
    
    // If we enter </item>
    if($tagname == "ITEM") {
        if(empty($this->description)) $this->description = "none";
        if(empty($this->pubdate)) $this->pubdate = "unknown";

        // Show the news
        printf("<b><a href='%s'>%s</a></b><br>", trim($this->link),htmlspecialchars(trim($this->title)));

        // You could also show the Publication date....

    // Empty the vars for new values

    unset($this->title);
    unset($this->description);
    unset($this->link);
    unset($this->pubdate);

    }

    // If we enter </channel>
    elseif($tagname == "CHANNEL") {
            if(empty($this->channel_copyright)) $this->copyright = "unknown";
            if(empty($this->channel_managingeditor)) $this->channel_managingeditor = "unknown";
            if(empty($this->channel_language)) $this->channel_language = "unknown";
            if(empty($this->channel_lastbuilddate)) $this->channel_lastbuilddate = "unknown";

            // We could show the RSS information here, it's up to yourself do it
    }
}


// Collect information and put it in the variables
function characterData($parser, $data) {

       if($this->flag == 1) { // entering <channel>
            switch($this->tag) {
                case
"LANGUAGE":
                    $this->channel_language .= $data;
                break;
                case
"LASTBUILDDATE":
                    $this->channel_lastbuilddate .= $data;
                break;
                case
"COPYRIGHT":
                    $this->channel_copyright .= $data;
                break;
                case
"MANAGINGEDITOR":
                    $this->channel_managingeditor .= $data;
                break;
            }
        }

       elseif($this->flag == 2) {
           switch($this->tag) { // entering <item>
                case "TITLE":
                    $this->title .= $data;
                break;
                case
"DESCRIPTION":
                    $this->description .= $data;
                break;
                case
"LINK":
                    $this->link .= $data;
                break;
                case
"PUBDATE":
                    $this->pubdate .= $data;
                break;
           }
       }
    }
}


// Create XML support and setup xml parser
$xp = xml_parser_create();
$rss_parser = new rss_parser();
xml_set_object($xp,&$rss_parser);

// Ignore whitespaces
xml_parser_set_option($xp, XML_OPTION_SKIP_WHITE, TRUE);

// Setup the start and end functions (Event handlers)
xml_set_element_handler($xp, "startElement", "endElement");
xml_set_character_data_handler($xp, "characterData");

    // Open xml file which contains the RSS info
    if($fp = @fopen($rss_file,"r")) {
        fflush($fp);

        // Read it in chunks of 4 kilobytes
        while($data = fread($fp, 4096)) {
            if(!(xml_parse($xp, trim($data), feof($fp))))
                die(sprintf("%s <b>%s</b>",PARSE, $rss_file));
        }

        // Close file pointer and free up the RSS parser cache info
        fclose($fp);
        xml_parser_free($xp);
    }

    else     // Error opening RSS file
    die(sprintf("%s <b>%s</b>",OPEN,$rss_file));
?>
Gewijzigd op 01/01/1970 01:00:00 door Lasse
 
PHP hulp

PHP hulp

22/12/2024 18:52:51
 
Luuk

luuk

22/01/2007 16:40:00
Quote Anchor link
op regel 61 <a href='%s'> veranderen in <a href='%s' target="_blank"> ?
 
Lasse

Lasse

22/01/2007 17:04:00
Quote Anchor link
Dit werkt helaas niet.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?
        // Show the news
        printf("<b><a href='%s' target="_blank">%s</a></b><br>", trim($this->link),htmlspecialchars(trim($this->title)));
?>


K vermoedt omdat " wordt gebruikt voor _blank werkt het niet.

Hopelijk heeft iemand nog een andere php manier om _blank te kunnen gebruiken?
Gewijzigd op 01/01/1970 01:00:00 door Lasse
 

22/01/2007 17:08:00
Quote Anchor link
Gaat fout met de quotes. Zo moet je hem veranderen:
<a href='%s' target='_blank'>
 
Lasse

Lasse

22/01/2007 17:11:00
Quote Anchor link
Ja het werkt bedankt!
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.