PHP and RSS Feed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martman

    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.


  • Phil Powell

    #2
    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@nos pam.insightbb.c om> wrote in message news:<31Jcc.208 068$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]

    Comment

    • Tim Tyler

      #3
      Re: PHP and RSS Feed

      Martman <martman100@nos pam.insightbb.c om> 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.

      Comment

      • Savut

        #4
        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.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


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

        Savut

        "Martman" <martman100@nos pam.insightbb.c om> wrote in message
        news:31Jcc.2080 68$po.1041362@a ttbi_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]

        Comment

        • Martman

          #5
          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($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" <webki@hotmail. com> wrote in message
          news:VpUcc.2372 $vf4.4829@news2 0.bellglobal.co m...[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.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[/color]
          of[color=blue]
          > the url everytime.
          >
          > Savut
          >
          > "Martman" <martman100@nos pam.insightbb.c om> wrote in message
          > news:31Jcc.2080 68$po.1041362@a ttbi_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]


          Comment

          • Martman

            #6
            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@nos pam.insightbb.c om> wrote in message
            news:1d0dc.2172 75$po.1072737@a ttbi_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($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'[/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='{$_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>
            > --------------------------------------------------------------------------[/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@news2 0.bellglobal.co m...[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.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[/color][/color]
            front[color=blue]
            > of[color=green]
            > > the url everytime.
            > >
            > > Savut
            > >
            > > "Martman" <martman100@nos pam.insightbb.c om> wrote in message
            > > news:31Jcc.2080 68$po.1041362@a ttbi_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]


            Comment

            • Tim Van Wassenhove

              #7
              Re: PHP and RSS Feed

              On 2004-04-08, Martman <martman100@nos pam.insightbb.c om> 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.ne t can be usefull too

              --

              Comment

              Working...