Need help with simple RSS praser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Oracle Porn
    Affiliate
    • Oct 2002
    • 24433

    #1

    Need help with simple RSS praser

    If anyone could help me that would be great
    My tube sites have rss feeds and I want to list latest videos on other sites, I need something simple and hopefully with cache, I found simpleRSS script but I couldn't get it to work probebly because I'm a noob at those things
    If anyone could help me that would be great, I can pay a few bucks if needed, icq is in my sig.


  • just a punk
    So fuckin' bored
    • Jun 2003
    • 32393

    #2
    Post your RSS URL here and I'll look at it.
    Obey the Cowgod

    Comment

    • Oracle Porn
      Affiliate
      • Oct 2002
      • 24433

      #3
      http://nubilestube.com/rss.php?location=most_recent


      Comment

      • just a punk
        So fuckin' bored
        • Jun 2003
        • 32393

        #4
        That's very easy. My code below (juts a few lines of PHP) will do the trick.

        Code:
        <?php
        $feed = file_get_contents ( "http://nubilestube.com/rss.php?location=most_recent" );
        $xml_parser = xml_parser_create ();
        xml_parse_into_struct ( $xml_parser, $feed, $vals, $index );
        $cnt = count ( $index ["TITLE"] );
        for($i = 1; $i < $cnt; $i ++) {
        	echo "<h3>" . html_entity_decode ( $vals [$index ["TITLE"] [$i]] ["value"], ENT_QUOTES ) . "</h3>\n";
        	echo "<p>" . html_entity_decode ( $vals [$index ["DESCRIPTION"] [$i]] ["value"], ENT_QUOTES ) . "</p>\n";
        }
        xml_parser_free ( $xml_parser );
        ?>
        Obey the Cowgod

        Comment

        • fris
          Too lazy to set a custom title
          • Aug 2002
          • 55679

          #5
          simple and effective code ;)
          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

          Comment

          • Oracle Porn
            Affiliate
            • Oct 2002
            • 24433

            #6
            thank you
            it works, although a bit slow because there's no caching
            how do I limit number of items parsed?


            Comment

            • just a punk
              So fuckin' bored
              • Jun 2003
              • 32393

              #7
              Here is the same code but with hourly cashing:

              Code:
              <?php
              $feed = file_get_contents ( "http://nubilestube.com/rss.php?location=most_recent" );
              $filename = "cache.txt";
              if (file_exists ( $filename ) && (time () - filectime ( $filename )) < 60 * 60) {
              	$content = file_get_contents ( $filename );
              } else {
              	$xml_parser = xml_parser_create ();
              	xml_parse_into_struct ( $xml_parser, $feed, $vals, $index );
              	$cnt = count ( $index ["TITLE"] );
              	$content = "";
              	for($i = 1; $i < $cnt; $i ++) {
              		$content .= "<h3>" . html_entity_decode ( $vals [$index ["TITLE"] [$i]] ["value"], ENT_QUOTES ) . "</h3>\n";
              		$content .= "<p>" . html_entity_decode ( $vals [$index ["DESCRIPTION"] [$i]] ["value"], ENT_QUOTES ) . "</p>\n";
              	}
              	file_put_contents($filename, $content, LOCK_EX);
              	xml_parser_free ( $xml_parser );
              }
              echo $content;
              ?>
              You just need to create the empty file "cache.txt" and chmod it to 666.

              Can't be easier, right?
              Obey the Cowgod

              Comment

              • just a punk
                So fuckin' bored
                • Jun 2003
                • 32393

                #8
                Originally posted by Oracle Porn
                thank you
                it works, although a bit slow because there's no caching
                See above.

                Originally posted by Oracle Porn
                how do I limit number of items parsed?
                Easily, simple replace this line:
                $cnt = count ( $index ["TITLE"] );

                to this one:
                $cnt = min ( 5, count ( $index ["TITLE"] ) );

                where 5 is your limit.
                Obey the Cowgod

                Comment

                • Oracle Porn
                  Affiliate
                  • Oct 2002
                  • 24433

                  #9
                  Originally posted by cyberxxx
                  Easily, simple replace this line:
                  $cnt = count ( $index ["TITLE"] );

                  to this one:
                  $cnt = min ( 5, count ( $index ["TITLE"] ) );

                  where 5 is your limit.
                  Awesome

                  Originally posted by cyberxxx
                  Here is the same code but with hourly cashing:

                  Code:
                  <?php
                  $feed = file_get_contents ( "http://nubilestube.com/rss.php?location=most_recent" );
                  $filename = "cache.txt";
                  if (file_exists ( $filename ) && (time () - filectime ( $filename )) < 60 * 60) {
                  	$content = file_get_contents ( $filename );
                  } else {
                  	$xml_parser = xml_parser_create ();
                  	xml_parse_into_struct ( $xml_parser, $feed, $vals, $index );
                  	$cnt = count ( $index ["TITLE"] );
                  	$content = "";
                  	for($i = 1; $i < $cnt; $i ++) {
                  		$content .= "<h3>" . html_entity_decode ( $vals [$index ["TITLE"] [$i]] ["value"], ENT_QUOTES ) . "</h3>\n";
                  		$content .= "<p>" . html_entity_decode ( $vals [$index ["DESCRIPTION"] [$i]] ["value"], ENT_QUOTES ) . "</p>\n";
                  	}
                  	file_put_contents($filename, $content, LOCK_EX);
                  	xml_parser_free ( $xml_parser );
                  }
                  echo $content;
                  ?>
                  You just need to create the empty file "cache.txt" and chmod it to 666.

                  Can't be easier, right?
                  This one doesn't work for me


                  Comment

                  • just a punk
                    So fuckin' bored
                    • Jun 2003
                    • 32393

                    #10
                    What's wrong with it? Did you create the "cache.txt" file and chmoded it properly?
                    Obey the Cowgod

                    Comment

                    • Oracle Porn
                      Affiliate
                      • Oct 2002
                      • 24433

                      #11
                      Yes I created the cache.txt file in the same folder and chmoded it to 666 (also tried 777)
                      Just outputs a blank page.
                      Last edited by Oracle Porn; 06-04-2011, 06:31 AM.


                      Comment

                      • just a punk
                        So fuckin' bored
                        • Jun 2003
                        • 32393

                        #12
                        Ah, now i see the problem. It's because the cache file is initially blank and it will update only after a hour

                        Here is a slightly fixed code:
                        Code:
                        <?php
                        $feed = file_get_contents ( "http://nubilestube.com/rss.php?location=most_recent" );
                        $filename = "cache.txt";
                        if (file_exists ( $filename ) && filesize ( $filename ) && (time () - filectime ( $filename )) < 60 * 60) {
                        	$content = file_get_contents ( $filename );
                        } else {
                        	$xml_parser = xml_parser_create ();
                        	xml_parse_into_struct ( $xml_parser, $feed, $vals, $index );
                        	$cnt = min ( 5, count ( $index ["TITLE"] ) );
                        	$content = "";
                        	for($i = 1; $i < $cnt; $i ++) {
                        		$content .= "<h3>" . html_entity_decode ( $vals [$index ["TITLE"] [$i]] ["value"], ENT_QUOTES ) . "</h3>\n";
                        		$content .= "<p>" . html_entity_decode ( $vals [$index ["DESCRIPTION"] [$i]] ["value"], ENT_QUOTES ) . "</p>\n";
                        	}
                        	file_put_contents ( $filename, $content, LOCK_EX );
                        	xml_parser_free ( $xml_parser );
                        }
                        echo $content;
                        ?>
                        Obey the Cowgod

                        Comment

                        • Oracle Porn
                          Affiliate
                          • Oct 2002
                          • 24433

                          #13
                          Perfect! Thanks I appreciate it


                          Comment

                          • just a punk
                            So fuckin' bored
                            • Jun 2003
                            • 32393

                            #14
                            You're welcome
                            Obey the Cowgod

                            Comment

                            • Oracle Porn
                              Affiliate
                              • Oct 2002
                              • 24433

                              #15
                              how do I add substr to the DESCRIPTION value?


                              Comment

                              • just a punk
                                So fuckin' bored
                                • Jun 2003
                                • 32393

                                #16
                                Originally posted by Oracle Porn
                                how do I add substr to the DESCRIPTION value?
                                Excuse me? What do you mean on "substr"?
                                Obey the Cowgod

                                Comment

                                Working...