Jump to content

PubDate time format help with RSS Parser


soggy

Recommended Posts

The format that is displaying is [b]Thu, 14 Dec 2006 17:31:00 GMT[/b]

I want it to display the date format as Dec 14, 2006 or close too. My php is below.

What needs to be added?

Thanks in advance




[code]<?php

class RSSParser  {

    var $title        = "";
    var $link          = "";
    var $description    = "";
    var $pubDate        = "";
    var $inside_item    = false;
    var $item_count    = 0;

    var $all_rss_urls = array(

                  );

  function startElement( $parser, $name, $attrs='' ){
      global $current_tag;

      $current_tag = $name;

      if( $current_tag == "ITEM" )
        $this->inside_item = true;

  } // endfunc startElement

  function endElement( $parser, $tagName, $attrs='' ){
      global $current_tag;

      if ( $tagName == "ITEM" ) {

          if ($this->item_count < 10) {
   
              printf( "\t<b><a href='%s' target='_blank'>%s</a></b>\n", trim( $this->link ), htmlspecialchars( trim( $this->title ) ) ); 
              printf( "\t%s<br>\n", htmlspecialchars( trim( $this->pubDate ) ) );
   
              $this->title = "";
              $this->description = "";
              $this->link = "";
      $this->pubDate = "";
              $this->inside_item = false;
          }


          $this->item_count ++;
      }

  } // endfunc endElement

  function characterData( $parser, $data ){
      global $current_tag;

      if( $this->inside_item ){
        switch($current_tag){

            case "TITLE":
              $this->title .= $data;
              break;
            case "DESCRIPTION":
              $this->description .= $data;
              break;
            case "LINK":
              $this->link .= $data;
              break;
            case "PUBDATE":
              $this->pubDate .= $data;
              break; 

            default:
              break;

        } // endswitch

      } // end if

  } // endfunc characterData

  function parse_results( $xml_parser, $rss_parser, $file )  {

      xml_set_object( $xml_parser, &$rss_parser );
      xml_set_element_handler( $xml_parser, "startElement", "endElement" );
      xml_set_character_data_handler( $xml_parser, "characterData" );

      $fp = fopen("$file","r") or die( "Error reading XML file, $file" );

      while ($data = fread($fp, 4096))  {

        // parse the data
        xml_parse( $xml_parser, $data, feof($fp) ) or die( sprintf( "XML error: %s at line %d", xml_error_string(

xml_get_error_code($xml_parser) ), xml_get_current_line_number( $xml_parser ) ) );

      } // endwhile

      fclose($fp);

      xml_parser_free( $xml_parser );

  } // endfunc parse_results

  function show_title( $rss_url ){
              ?>
              <?
  } // endfunc show_title

  function show_list_box( $rss_url ){

            ?>
      <?
  } // end func show_list_box

} // endclass RSSParser

global $rss_url;

// Set a default feed
if( $rss_url == "" )
  $rss_url = "http://www.dailycamera.com/feeds/headlines/sports/broncos/";
   

$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();

$rss_parser->show_title( $rss_url );
$rss_parser->parse_results( $xml_parser, &$rss_parser, $rss_url );
$rss_parser->show_list_box( $rss_url );

?> [/code]
Link to comment
https://forums.phpfreaks.com/topic/31841-pubdate-time-format-help-with-rss-parser/
Share on other sites

trying placing it before this:
          case "PUBDATE":
          $this->pubDate .= $data;
          break;
or anywhere else you feel it should be around, because trial and error is the best way to find the solution.
[quote author=ted_chou12 link=topic=119903.msg491489#msg491489 date=1167091893]
trying placing it before this:
           case "PUBDATE":
           $this->pubDate .= $data;
           break;
or anywhere else you feel it should be around, because trial and error is the best way to find the solution.
[/quote]

not working

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.