GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Need help with simple RSS praser (https://gfy.com/showthread.php?t=1025286)

Oracle Porn 06-04-2011 05:52 AM

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 06-04-2011 05:56 AM

Post your RSS URL here and I'll look at it.

Oracle Porn 06-04-2011 06:01 AM

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

just a punk 06-04-2011 06:06 AM

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 );
?>


fris 06-04-2011 06:13 AM

simple and effective code ;)

Oracle Porn 06-04-2011 06:29 AM

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

just a punk 06-04-2011 06:31 AM

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? :winkwink:

just a punk 06-04-2011 06:34 AM

Quote:

Originally Posted by Oracle Porn (Post 18193945)
thank you
it works, although a bit slow because there's no caching

See above.

Quote:

Originally Posted by Oracle Porn (Post 18193945)
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.

Oracle Porn 06-04-2011 07:01 AM

Quote:

Originally Posted by cyberxxx (Post 18193954)
Easily, simple replace this line:
$cnt = count ( $index ["TITLE"] );

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

where 5 is your limit.

Awesome :thumbsup

Quote:

Originally Posted by cyberxxx (Post 18193948)
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? :winkwink:

This one doesn't work for me :(

just a punk 06-04-2011 07:15 AM

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

Oracle Porn 06-04-2011 07:26 AM

Yes I created the cache.txt file in the same folder and chmoded it to 666 (also tried 777)
Just outputs a blank page.

just a punk 06-04-2011 07:38 AM

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;
?>


Oracle Porn 06-04-2011 08:35 AM

Perfect! Thanks I appreciate it :)

just a punk 06-04-2011 08:38 AM

You're welcome :)

Oracle Porn 09-15-2011 09:15 AM

how do I add substr to the DESCRIPTION value?

just a punk 10-07-2011 06:28 AM

Quote:

Originally Posted by Oracle Porn (Post 18429484)
how do I add substr to the DESCRIPTION value?

Excuse me? What do you mean on "substr"?


All times are GMT -7. The time now is 06:11 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123