homepage Welcome to WebmasterWorld Guest from 54.234.141.47
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

    
Making link from RSS feed pop-up
Want to use a target=_blank type statement in PHP
moishe

10+ Year Member



 
Msg#: 92 posted 2:44 pm on Sep 8, 2004 (gmt 0)

I am using the following to put RSS feeds on my site, does anyone know how to make the links generated by the RSS open in a new window?....

<?php

$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $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("h$$p://rss.example.net/rss/world/virgin-islands.xml","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
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);

?>

 

rincey

10+ Year Member



 
Msg#: 92 posted 11:04 am on Sep 9, 2004 (gmt 0)

In the line starting with
printf("<dt><b><a href='%s'>%s</a></b></dt>",
in the function endElement() just change the
<a href='%s'>
to
<a href='%s' target='_blank'>

This should do the job.

Ad

moishe

10+ Year Member



 
Msg#: 92 posted 3:04 pm on Sep 9, 2004 (gmt 0)

Thank you very much.

BTW, anyone looking for an easy way to put an RSS feed on your page (G indexes it just fine), is welcome to use this script. Just change $fp = fopen("h$$p://rss.example.net/rss/world/virgin-islands.xml","r")
to the url for the feed you want.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved