473,831 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP and RSS Feed

I am new to PHP but testing the ability to read an RSS xml feed. I have
successfully retrieved, read, and displayed an RSS feed from pcworld.
However, when you click on one of the links it adds http://localhost to the
link located in the xml file. If I view source in the browser everything
appears okay.

Does anyone know of a configuration in the apache or php config files that
automatically adds http://localhost to hyperlinks?

If not, has anyone seen any similar problems while reading an xml feed?

Thanks
Marty U.
Jul 17 '05 #1
6 2323
I am running RSS Feed on my website using PHP with no problems,
course, everything is written by me customized. I've never
encountered such a problem; you might look into the way you're
configuring your RSS.

Phil

"Martman" <ma********@nos pam.insightbb.c om> wrote in message news:<31Jcc.208 068$po.1041362@ attbi_s52>...
I am new to PHP but testing the ability to read an RSS xml feed. I have
successfully retrieved, read, and displayed an RSS feed from pcworld.
However, when you click on one of the links it adds http://localhost to the
link located in the xml file. If I view source in the browser everything
appears okay.

Does anyone know of a configuration in the apache or php config files that
automatically adds http://localhost to hyperlinks?

If not, has anyone seen any similar problems while reading an xml feed?

Thanks
Marty U.

Jul 17 '05 #2
Martman <ma********@nos pam.insightbb.c om> wrote or quoted:
I am new to PHP but testing the ability to read an RSS xml feed. I have
successfully retrieved, read, and displayed an RSS feed from pcworld.
However, when you click on one of the links it adds http://localhost to the
link located in the xml file. If I view source in the browser everything
appears okay.

Does anyone know of a configuration in the apache or php config files that
automatically adds http://localhost to hyperlinks?

If not, has anyone seen any similar problems while reading an xml feed?


What software are you using to parse the feed?
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #3
I guess it's because your application use a urlencode() somewhere.

Exemple 1:
$encodedLink = urlencode("http ://www.rssfeed.com/articleX.php");
echo ("http://www.mydomain.co m/go.php?site=$en codedLink");
// and go.php do the redirect, this will work

Exemple 2:
echo ("<a href='http://www.rssfeed.com/articleX.php'>L ink</a>");
// this will work

Exemple 3:
$encodedLink = urlencode("http ://www.rssfeed.com ");
echo ("<a href='$encodedL ink'>Link</a>");
// this wont work

This will result something like
http://www.mydomain.com/http%3A%2F%2...2FarticleX.php

And I guess you test locally, that's why you get htt://localhost in front of
the url everytime.

Savut

"Martman" <ma********@nos pam.insightbb.c om> wrote in message
news:31Jcc.2080 68$po.1041362@a ttbi_s52...
I am new to PHP but testing the ability to read an RSS xml feed. I have
successfully retrieved, read, and displayed an RSS feed from pcworld.
However, when you click on one of the links it adds http://localhost to
the
link located in the xml file. If I view source in the browser everything
appears okay.

Does anyone know of a configuration in the apache or php config files that
automatically adds http://localhost to hyperlinks?

If not, has anyone seen any similar problems while reading an xml feed?

Thanks
Marty U.


Jul 17 '05 #4
I did not find urlencode via Dreamweaver search function, so here is the
actual php page that is parsing the pcworld xml file:
----------------------------------------------------------------------------
----
<?

$_item = array();
$_depth = array();
$_tags = array("dummy");
/* "dummy" prevents unecessary subtraction
* in the $_depth indexes */
function initArray()
{
global $_item;

$_item = array ("TITLE"=>"" , "LINK"=>"",
"DESCRIPTION"=> "", "URL"=>"");
}

function startElement($p arser, $name)

{
global $_depth, $_tags, $_item;

if (($name=="ITEM" ) || ($name=="CHANNE L")
|| ($name=="IMAGE" )) {
initArray();
}
$_depth[$parser]++;
array_push($_ta gs, $name);
}

function endElement($par ser, $name)

{
global $_depth, $_tags, $_item;

array_pop($_tag s);
$_depth[$parser]--;
switch ($name) {
case "ITEM":
echo "<li><a style='font-family: Arial;font-size: .75em' href='
{$_item['LINK']}' title='{$_item['TITLE']}'>" .
"{$_item['TITLE']}</a></li>\n";
initArray();
break;

case "IMAGE":
echo "<a href='{$_item['LINK']}'>" .
"<DEFANGED_ IMG src='{$_item['URL']}' " .
"alt='{$_it em['TITLE']}; border='0'></a>\n<br />\n";
initArray();
break;

case "CHANNEL":
echo "<h4>{$_ite m['TITLE']}</h4>\n";
initArray();
break;
}
}

function parseData($pars er, $text)
{
global $_depth, $_tags, $_item;

$crap = preg_replace ("/\s/", "", $text);
/* is the data just whitespace?
if so, we don't want it! */

if ($crap) {
$text = preg_replace ("/^\s+/", "", $text);
/* get rid of leading whitespace */
if ($_item[$_tags[$_depth[$parser]]]) {
$_item[$_tags[$_depth[$parser]]] .= $text;
} else {
$_item[$_tags[$_depth[$parser]]] = $text;
}
}
}
function parseRDF($file)
{
global $_depth, $_tags, $_item;

$xml_parser = xml_parser_crea te();
initArray();

/* Set up event handlers */
xml_set_element _handler($xml_p arser, "startEleme nt", "endElement ");
xml_set_charact er_data_handler ($xml_parser, "parseData" );

/* Open up the file */
$fp = fopen ($file, "r") or die ("Could not open $file for input");

while ($data = fread ($fp, 4096)) {
if (!xml_parse($xm l_parser, $data, feof($fp))) {
die (sprintf("XML error: %s at line %d",
xml_error_strin g(xml_get_error _code ($xml_parser)),
xml_get_current _line_number($x ml_parser)));
}
}

fclose($fp);
xml_parser_free ($xml_parser);
}
?>
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
parseRDF("http://rss.pcworld.com/rss/pg_feed.rss?pgi d=30");
?>
</body>
</html>
----------------------------------------------------------------------------
--------

You can view the xml rss feed by visiting the link above.

Thanks for any help this has me confused as to why it would be adding the
current path to the link.

Marty

"Savut" <we***@hotmail. com> wrote in message
news:Vp******** *********@news2 0.bellglobal.co m...
I guess it's because your application use a urlencode() somewhere.

Exemple 1:
$encodedLink = urlencode("http ://www.rssfeed.com/articleX.php");
echo ("http://www.mydomain.co m/go.php?site=$en codedLink");
// and go.php do the redirect, this will work

Exemple 2:
echo ("<a href='http://www.rssfeed.com/articleX.php'>L ink</a>");
// this will work

Exemple 3:
$encodedLink = urlencode("http ://www.rssfeed.com ");
echo ("<a href='$encodedL ink'>Link</a>");
// this wont work

This will result something like
http://www.mydomain.com/http%3A%2F%2...2FarticleX.php

And I guess you test locally, that's why you get htt://localhost in front of the url everytime.

Savut

"Martman" <ma********@nos pam.insightbb.c om> wrote in message
news:31Jcc.2080 68$po.1041362@a ttbi_s52...
I am new to PHP but testing the ability to read an RSS xml feed. I have
successfully retrieved, read, and displayed an RSS feed from pcworld.
However, when you click on one of the links it adds http://localhost to
the
link located in the xml file. If I view source in the browser everything
appears okay.

Does anyone know of a configuration in the apache or php config files that automatically adds http://localhost to hyperlinks?

If not, has anyone seen any similar problems while reading an xml feed?

Thanks
Marty U.

Jul 17 '05 #5
Nevermind, found the problem:
echo "<li><a style='font-family: Arial;font-size: .75em' href='
{$_item['LINK']}' title='{$_item['TITLE']}'>" .
"{$_item['TITLE']}</a></li>\n"; The single apostrophe after the href was actually not an apostrophe, I could
see the difference in dreamweaver. It must be a character issue when I
copied the code.

thanks for any help.

"Martman" <ma********@nos pam.insightbb.c om> wrote in message
news:1d0dc.2172 75$po.1072737@a ttbi_s52... I did not find urlencode via Dreamweaver search function, so here is the
actual php page that is parsing the pcworld xml file:
-------------------------------------------------------------------------- -- ----
<?

$_item = array();
$_depth = array();
$_tags = array("dummy");
/* "dummy" prevents unecessary subtraction
* in the $_depth indexes */
function initArray()
{
global $_item;

$_item = array ("TITLE"=>"" , "LINK"=>"",
"DESCRIPTION"=> "", "URL"=>"");
}

function startElement($p arser, $name)

{
global $_depth, $_tags, $_item;

if (($name=="ITEM" ) || ($name=="CHANNE L")
|| ($name=="IMAGE" )) {
initArray();
}
$_depth[$parser]++;
array_push($_ta gs, $name);
}

function endElement($par ser, $name)

{
global $_depth, $_tags, $_item;

array_pop($_tag s);
$_depth[$parser]--;
switch ($name) {
case "ITEM":
echo "<li><a style='font-family: Arial;font-size: .75em' href=' {$_item['LINK']}' title='{$_item['TITLE']}'>" .
"{$_item['TITLE']}</a></li>\n";
initArray();
break;

case "IMAGE":
echo "<a href='{$_item['LINK']}'>" .
"<DEFANGED_ IMG src='{$_item['URL']}' " .
"alt='{$_it em['TITLE']}; border='0'></a>\n<br />\n";
initArray();
break;

case "CHANNEL":
echo "<h4>{$_ite m['TITLE']}</h4>\n";
initArray();
break;
}
}

function parseData($pars er, $text)
{
global $_depth, $_tags, $_item;

$crap = preg_replace ("/\s/", "", $text);
/* is the data just whitespace?
if so, we don't want it! */

if ($crap) {
$text = preg_replace ("/^\s+/", "", $text);
/* get rid of leading whitespace */
if ($_item[$_tags[$_depth[$parser]]]) {
$_item[$_tags[$_depth[$parser]]] .= $text;
} else {
$_item[$_tags[$_depth[$parser]]] = $text;
}
}
}
function parseRDF($file)
{
global $_depth, $_tags, $_item;

$xml_parser = xml_parser_crea te();
initArray();

/* Set up event handlers */
xml_set_element _handler($xml_p arser, "startEleme nt", "endElement ");
xml_set_charact er_data_handler ($xml_parser, "parseData" );

/* Open up the file */
$fp = fopen ($file, "r") or die ("Could not open $file for input");

while ($data = fread ($fp, 4096)) {
if (!xml_parse($xm l_parser, $data, feof($fp))) {
die (sprintf("XML error: %s at line %d",
xml_error_strin g(xml_get_error _code ($xml_parser)),
xml_get_current _line_number($x ml_parser)));
}
}

fclose($fp);
xml_parser_free ($xml_parser);
}
?>
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
parseRDF("http://rss.pcworld.com/rss/pg_feed.rss?pgi d=30");
?>
</body>
</html>
-------------------------------------------------------------------------- -- --------

You can view the xml rss feed by visiting the link above.

Thanks for any help this has me confused as to why it would be adding the
current path to the link.

Marty

"Savut" <we***@hotmail. com> wrote in message
news:Vp******** *********@news2 0.bellglobal.co m...
I guess it's because your application use a urlencode() somewhere.

Exemple 1:
$encodedLink = urlencode("http ://www.rssfeed.com/articleX.php");
echo ("http://www.mydomain.co m/go.php?site=$en codedLink");
// and go.php do the redirect, this will work

Exemple 2:
echo ("<a href='http://www.rssfeed.com/articleX.php'>L ink</a>");
// this will work

Exemple 3:
$encodedLink = urlencode("http ://www.rssfeed.com ");
echo ("<a href='$encodedL ink'>Link</a>");
// this wont work

This will result something like
http://www.mydomain.com/http%3A%2F%2...2FarticleX.php

And I guess you test locally, that's why you get htt://localhost in front
of
the url everytime.

Savut

"Martman" <ma********@nos pam.insightbb.c om> wrote in message
news:31Jcc.2080 68$po.1041362@a ttbi_s52...
I am new to PHP but testing the ability to read an RSS xml feed. I have
successfully retrieved, read, and displayed an RSS feed from pcworld.
However, when you click on one of the links it adds http://localhost to the
link located in the xml file. If I view source in the browser everything appears okay.

Does anyone know of a configuration in the apache or php config files

that automatically adds http://localhost to hyperlinks?

If not, has anyone seen any similar problems while reading an xml feed?
Thanks
Marty U.


Jul 17 '05 #6
On 2004-04-08, Martman <ma********@nos pam.insightbb.c om> wrote:
Nevermind, found the problem:
echo "<li><a style='font-family: Arial;font-size: .75em' href='
{$_item['LINK']}' title='{$_item['TITLE']}'>" .
"{$_item['TITLE']}</a></li>\n";

The single apostrophe after the href was actually not an apostrophe, I could
see the difference in dreamweaver. It must be a character issue when I
copied the code.


magpierss.sf.ne t can be usefull too

--
http://home.mysth.be/~timvw
Jul 17 '05 #7

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

Similar topics

0
1427
by: Kraft Bernhard | last post by:
Hallo list, I don't know if this is a apropriate Newsgroup for this thread but I found it via google and there are already some RSS question in here so I'm just asking: I have written a RSS Feed which fetches the list of new Extensions for the CMS Typo3 (www.typo3.org) and stores them in a database. Whenever somebody requests the RSS Feed the Feed XML is generated out of the database.
2
4299
by: Brad Sanders | last post by:
Hello All, Thanks to Richard's answer to my last post I understand now what I have to do, but.. How do I put a Line Feed or a Form Feed into a text file? Looking throught the .net help it mentions \f but illustrates no way write it to a text file. Thanks
1
2577
by: Steve | last post by:
I have a script that has been modified from one that I found on the internet to display RSS feeds in html. The script works fine for most RSS feeds but there are a number that it fails on with the error "End tag 'head' does not match the start tag 'meta'". Does any one on here have any experience with this? The script is shown below, the Neowin feed works but the google feed does not. Any help would be appreciated.
6
2373
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 javascript into the XML source would work.
4
4236
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
5
2437
by: Ed Flecko | last post by:
Hi folks, I'm trying to figure out this whole RSS feed thing. I've created my .xml file to use for my feed, and my browsers "recognize" that I have an RSS feed, and you can subscribe, etc., etc. Here's why I "think" I want to use an RSS feed, and what I'm confused about. I have one file (and one file only) on my web site that changes
1
1652
by: paul.hester | last post by:
Hi all, I work for a classified-type site and am planning on having an RSS feed for each category. I understand the basics of RSS, but I can't decide how often to update each RSS feed. Each category will probably have several new listings every hour. What's generally the recommended update frequency for an RSS feed? Also, in each update, do you exclude content that was in previous feeds, or do you leave it up to the reader to sort out...
4
1971
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
10
2397
by: bhass | last post by:
From my other post I am making a simple program that creates an RSS feed with Python. Now when I run my program so far, I get errors. It says "something is not defined". The word something is replaced by the name of the function I'm trying to use. my article function when ran, comes up with "article is not defined" etc. Here's my code: What is wrong with it? #!/usr/bin/env python import ftplib import getpass def mainfeed(): ...
2
3234
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 THERE ARE NEW POSTS, ADD THEM TO THE DATABASE ///// public function feed($feed,$type) { if...
0
9642
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10494
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10534
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10207
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9317
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5619
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.