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!


<? 
/* 
############################################################################## 
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)); 
?> 
op regel 61 <a href='%s'> veranderen in <a href='%s' target="_blank"> ?
Dit werkt helaas niet.


<?
        // 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?
Gaat fout met de quotes. Zo moet je hem veranderen:
<a href='%s' target='_blank'>
Ja het werkt bedankt!

Reageren