By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,744 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,744 IT Pros & Developers. It's quick & easy.

PHP and RSS Feed

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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********@nospam.insightbb.com> wrote in message news:<31Jcc.208068$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

P: n/a
Martman <ma********@nospam.insightbb.com> 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

P: n/a
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" <ma********@nospam.insightbb.com> wrote in message
news:31Jcc.208068$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 #4

P: n/a
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" <we***@hotmail.com> wrote in message
news:Vp*****************@news20.bellglobal.com...
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" <ma********@nospam.insightbb.com> wrote in message
news:31Jcc.208068$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 #5

P: n/a
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********@nospam.insightbb.com> wrote in message
news:1d0dc.217275$po.1072737@attbi_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($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" <we***@hotmail.com> wrote in message
news:Vp*****************@news20.bellglobal.com...
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" <ma********@nospam.insightbb.com> wrote in message
news:31Jcc.208068$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 #6

P: n/a
On 2004-04-08, Martman <ma********@nospam.insightbb.com> 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.net can be usefull too

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

This discussion thread is closed

Replies have been disabled for this discussion.