473,570 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

News feed webpage ?

Hi everyone !

I am a newbie to this newsgroup. I would appreciate if someone can help
me to solve this problem.

OK, I am currently writing a webpage in PHP that will get RSS file(XML
file) (news feed) and parse it using PHP and display articles' link and
description. I want everytime a user click on one article's link, it
take the user to another page which was written by me (for example,
"display.php?ai d=43232") (I don't want user to leave my website) and
pass the article ID to the URL string. Everything run fine at this
point but I got duplicate filename on the URL
("display.php?a id=43232&displa y.php="). I don't know how to fix this.

Here is the code.
=============== === Code for RSS parsing =============== =======
//This code was copied from the following tutorial.
//http://www.sitepoint.c om/article/php-xml-parsing-rss-1-0

<html>
<head>
<title> The core </title>
</head>
<body>
<dl>
<?php

class RSSParser {

var $insideitem = false;
var $tag = "";
var $title = "";
var $description = "";
var $link = "";
function startElement($p arser, $tagName, $attrs) {
if ($this->insideitem) {
$this->tag = $tagName;
} elseif ($tagName == "ITEM") {
$this->insideitem = true;
}
}

function endElement($par ser, $tagName) {
if ($tagName == "ITEM") {

printf("<dt><b> <a href='%s'>%s</a></b></dt>",
trim($this->link),htmlspec ialchars(trim($ this->title)));

printf("<dd>%s</dd>",htmlspecia lchars(trim($th is->description))) ;
$this->title = "";
$this->description = "";
$this->link = "";
$this->insideitem = false;

}
}

function characterData($ parser, $data) {
if ($this->insideitem) {
switch ($this->tag) {
case "TITLE":
$this->title .= $data;
break;
case "DESCRIPTIO N":
$this->description .= $data;
break;
//edit the link here
case "LINK":
{
//$this->link .= $data
$id = $this->newLink($data) ;
$this->link .= "display.php?ai d="."$id&";
break;
}
}
}
}
function newLink($newsli nk)
{
$file_name = basename($newsl ink, ".php");
$id = ereg_replace("[^0-9]", "", $file_name);

return $id;
}
}

$xml_parser = xml_parser_crea te();
$rss_parser = new RSSParser();
xml_set_object( $xml_parser,&$r ss_parser);
xml_set_element _handler($xml_p arser, "startEleme nt", "endElement ");
xml_set_charact er_data_handler ($xml_parser, "characterData" );
$fp = fopen("http://www.prweb.com/rss2/computers.xml", "r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_ parser, $data, feof($fp))
or die(sprintf("XM L error: %s at line %d",
xml_error_strin g(xml_get_error _code($xml_pars er)),
xml_get_current _line_number($x ml_parser)));
fclose($fp);
xml_parser_free ($xml_parser);

?>
</dl>
</body>
</html>

=============== =============== =============== ====

========= Code for display.php =========
<?php

echo "<h1>Displa y news </h1>";

$id = $_GET["aid"];

$baseLink = "http://www.prweb.com/printer.php?pri d=";

include($baseLi nk.$id);

?>
=============== =============== ==========

Thank you in advance .

John Lam

Jul 17 '05 #1
4 1782
John wrote:
OK, I am currently writing a webpage in PHP that will get RSS
file(XML file) (news feed) and parse it using PHP and display
articles' link and description. I want everytime a user click on one
article's link, it take the user to another page which was written by
me (for example, "display.php?ai d=43232") (I don't want user to leave
my website) and pass the article ID to the URL string. Everything run
fine at this point but I got duplicate filename on the URL
("display.php?a id=43232&displa y.php="). I don't know how to fix this.


The feed is indented, which creates so called text nodes between the
elements.

To skip these nodes on a non-Windows environment, you can apply:

xml_parser_set_ option($xml_par ser, XML_OPTION_SKIP _WHITE, 1);

When you are working on a Windows box, you can do something like:

case "LINK" && trim($data): {
...
}
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
When you are working on a Windows box, you can do something like:

case "LINK" && trim($data): {
...
}


In this case, you should assign the value to the $this->link variable,
rather then concatenate it:

case "LINK" && trim($data): {
$id = $this->newLink($data) ;
$this->link = "display.php?ai d=$id";
break;
}
JW

Jul 17 '05 #3
John wrote:
OK, I am currently writing a webpage in PHP that will get RSS file(XML
file) (news feed) and parse it using PHP and display articles' link and
description.


Any reason not to use the existing code:
http://pear.php.net/manual/en/package.xml.xml-rss.php

/Marcin
Jul 17 '05 #4
Great help. It works. Thanks everyone !

John Lam

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3438
by: Zhang Le | last post by:
Hello, I'm writing a little Tkinter application to retrieve news from various news websites such as http://news.bbc.co.uk/, and display them in a TK listbox. All I want are news title and url information. Since each news site has a different layout, I think I need some template-based techniques to build news extractors for each site,...
1
2724
by: it hates me | last post by:
Hey gang, I hope you're all well and you're having an enjoyable week I'd love to be able to have a custom news feed on my web page through Javascript The only custom news feed I can find for free is from Yahoo. Are there any more? Now, for my web page I can get this to work fine:
0
1595
by: Jon | last post by:
All, I'm extremely new to XML and have been given a project that at this time seems way over my head. Was hoping someone here could help. Basically, I need a page that functions much like pages at www.feedburner.com. When you publish a feed, users can click on any files associated with the feed that are displayed in a nice looking webpage...
5
9353
by: sck10 | last post by:
Hello, I am using the following to get RSS Feeds. I've been able to get the xml files from every site except CNN. When I try to get there feed, I get the exception: A column named 'link' already belongs to this DataTable: cannot set a nested table name to the same name. Any help with this would be appreciated. Thanks, sck10
6
2367
by: affiliateian | last post by:
Total newbie here for this so please be patient. We manually update our XML feed when we publish an article on our website. Can we add a javascript tracking pixel (from phpadsnew) into the XML file to track how many times our feed was accessed? Just to get a rough idea how manyh subscribers we have? Not sure if copying and pasting a...
4
4217
by: Florian Lindner | last post by:
Hello, I'm looking for python RSS feed parser library. Feedparser http://feedparser.org/ does not seem to maintained anymore. What alternatives are recommendable? Thanks, Florian
1
1992
by: Ellie | last post by:
I need to be able to get a feed and then have it displayed on my website. I'm not sure if I can get the feed, but if I can, what would be the best way to create a web page from the feed? Also, if I can't get the feed, I can get daily email updates of google group posts. If I have the email, how could I get that on the webserver so that the web...
4
1940
by: Blake Garner | last post by:
I'm looking for suggestions on how to approach generating rss feed ..xml files using python. What modules to people recommend I start with? Thanks! Blake
2
3206
jamwil
by: jamwil | last post by:
What's up guys. I'm having some issues... I've created a method as part of my lifestreaming class which takes an rss feed, and puts the data into a database... It's fairly simple... Check it....///// // feed // // LOADS THE RSS FEED FOR // LOOPS THROUGH AND FORMATS/FILTERS POSTS // PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB // IF...
0
7636
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8150
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7700
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.