Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP and RSS Feed

Martman
Guest
 
Posts: n/a
#1: Jul 17 '05
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.



Phil Powell
Guest
 
Posts: n/a
#2: Jul 17 '05

re: PHP and RSS Feed


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" <martman100@nospam.insightbb.com> wrote in message news:<31Jcc.208068$po.1041362@attbi_s52>...[color=blue]
> 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.[/color]
Tim Tyler
Guest
 
Posts: n/a
#3: Jul 17 '05

re: PHP and RSS Feed


Martman <martman100@nospam.insightbb.com> wrote or quoted:
[color=blue]
> 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?[/color]

What software are you using to parse the feed?
--
__________
|im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
Savut
Guest
 
Posts: n/a
#4: Jul 17 '05

re: PHP and RSS Feed


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.com/go.php?site=$encodedLink");
// and go.php do the redirect, this will work

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

Exemple 3:
$encodedLink = urlencode("http://www.rssfeed.com");
echo ("<a href='$encodedLink'>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" <martman100@nospam.insightbb.com> wrote in message
news:31Jcc.208068$po.1041362@attbi_s52...[color=blue]
>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.
>
>[/color]

Martman
Guest
 
Posts: n/a
#5: Jul 17 '05

re: PHP and RSS Feed


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($parser, $name)

{
global $_depth, $_tags, $_item;

if (($name=="ITEM") || ($name=="CHANNEL")
|| ($name=="IMAGE")) {
initArray();
}
$_depth[$parser]++;
array_push($_tags, $name);
}

function endElement($parser, $name)

{
global $_depth, $_tags, $_item;

array_pop($_tags);
$_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='{$_item['TITLE']}; border='0'></a>\n<br />\n";
initArray();
break;

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

function parseData($parser, $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_create();
initArray();

/* Set up event handlers */
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_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($xml_parser, $data, feof($fp))) {
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);
}
?>
<html>
<head>
<title>Untitled 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?pgid=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" <webki@hotmail.com> wrote in message
news:VpUcc.2372$vf4.4829@news20.bellglobal.com...[color=blue]
> 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.com/go.php?site=$encodedLink");
> // and go.php do the redirect, this will work
>
> Exemple 2:
> echo ("<a href='http://www.rssfeed.com/articleX.php'>Link</a>");
> // this will work
>
> Exemple 3:
> $encodedLink = urlencode("http://www.rssfeed.com");
> echo ("<a href='$encodedLink'>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[/color]
of[color=blue]
> the url everytime.
>
> Savut
>
> "Martman" <martman100@nospam.insightbb.com> wrote in message
> news:31Jcc.208068$po.1041362@attbi_s52...[color=green]
> >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[/color][/color]
that[color=blue][color=green]
> > automatically adds http://localhost to hyperlinks?
> >
> > If not, has anyone seen any similar problems while reading an xml feed?
> >
> > Thanks
> > Marty U.
> >
> >[/color]
>[/color]


Martman
Guest
 
Posts: n/a
#6: Jul 17 '05

re: PHP and RSS Feed


Nevermind, found the problem:
echo "<li><a style='font-family: Arial;font-size: .75em' href='[color=blue]
> {$_item['LINK']}' title='{$_item['TITLE']}'>" .
> "{$_item['TITLE']}</a></li>\n";[/color]
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" <martman100@nospam.insightbb.com> wrote in message
news:1d0dc.217275$po.1072737@attbi_s52...[color=blue]
> I did not find urlencode via Dreamweaver search function, so here is the
> actual php page that is parsing the pcworld xml file:
> --------------------------------------------------------------------------[/color]
--[color=blue]
> ----
> <?
>
> $_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($parser, $name)
>
> {
> global $_depth, $_tags, $_item;
>
> if (($name=="ITEM") || ($name=="CHANNEL")
> || ($name=="IMAGE")) {
> initArray();
> }
> $_depth[$parser]++;
> array_push($_tags, $name);
> }
>
> function endElement($parser, $name)
>
> {
> global $_depth, $_tags, $_item;
>
> array_pop($_tags);
> $_depth[$parser]--;
> switch ($name) {
> case "ITEM":
> echo "<li><a style='font-family: Arial;font-size: .75em'[/color]
href='[color=blue]
> {$_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='{$_item['TITLE']}; border='0'></a>\n<br />\n";
> initArray();
> break;
>
> case "CHANNEL":
> echo "<h4>{$_item['TITLE']}</h4>\n";
> initArray();
> break;
> }
> }
>
> function parseData($parser, $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_create();
> initArray();
>
> /* Set up event handlers */
> xml_set_element_handler($xml_parser, "startElement", "endElement");
> xml_set_character_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($xml_parser, $data, feof($fp))) {
> 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);
> }
> ?>
> <html>
> <head>
> <title>Untitled 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?pgid=30");
> ?>
> </body>
> </html>
> --------------------------------------------------------------------------[/color]
--[color=blue]
> --------
>
> 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" <webki@hotmail.com> wrote in message
> news:VpUcc.2372$vf4.4829@news20.bellglobal.com...[color=green]
> > 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.com/go.php?site=$encodedLink");
> > // and go.php do the redirect, this will work
> >
> > Exemple 2:
> > echo ("<a href='http://www.rssfeed.com/articleX.php'>Link</a>");
> > // this will work
> >
> > Exemple 3:
> > $encodedLink = urlencode("http://www.rssfeed.com");
> > echo ("<a href='$encodedLink'>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[/color][/color]
front[color=blue]
> of[color=green]
> > the url everytime.
> >
> > Savut
> >
> > "Martman" <martman100@nospam.insightbb.com> wrote in message
> > news:31Jcc.208068$po.1041362@attbi_s52...[color=darkred]
> > >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[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > the
> > > link located in the xml file. If I view source in the browser[/color][/color][/color]
everything[color=blue][color=green][color=darkred]
> > > appears okay.
> > >
> > > Does anyone know of a configuration in the apache or php config files[/color][/color]
> that[color=green][color=darkred]
> > > automatically adds http://localhost to hyperlinks?
> > >
> > > If not, has anyone seen any similar problems while reading an xml[/color][/color][/color]
feed?[color=blue][color=green][color=darkred]
> > >
> > > Thanks
> > > Marty U.
> > >
> > >[/color]
> >[/color]
>
>[/color]


Tim Van Wassenhove
Guest
 
Posts: n/a
#7: Jul 17 '05

re: PHP and RSS Feed


On 2004-04-08, Martman <martman100@nospam.insightbb.com> wrote:[color=blue]
> Nevermind, found the problem:
> echo "<li><a style='font-family: Arial;font-size: .75em' href='[color=green]
>> {$_item['LINK']}' title='{$_item['TITLE']}'>" .
>> "{$_item['TITLE']}</a></li>\n";[/color]
> 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.[/color]

magpierss.sf.net can be usefull too

--
http://home.mysth.be/~timvw
Closed Thread