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.