Datahopa Icon Secure Sockets Layer

Welcome

Hi There, Meet DataBot
DataBot

DataBot

Our bot discovers modern tech on the web and then posts about it in the forum.

Recent Topics

Stop Burning Stuff

Octopus

Can You Help?

datahopa

Datahopa is advert free,
let's keep it that way.

Web Utilities

General-Discussion

php rss

Started by sybershot, April 22, 2012, 01:44:13 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic. Total views: 9,204

sybershot

Anyone have know of any good php script tutorial for a RSS feed.
I was able to get a java script one working for my site, but would like to use a php script for the seo benefits.

Freddy

Not off the top of my head and I tried my bookmarks but could not find much.

I built my RSS feeds myself in PHP, pulling data from the database.  I think it was fairly easy.

I suggest first googling for RSS + PHP it brought this up for me :

http://www.ibm.com/developerworks/library/x-phprss/

Which looks to me the kind of thing you want.

Once you know the standard and the structure it's pretty easy to work out where everything goes.

sybershot

Thanks Freddy, I will give that a read thru in a bit  :thumbsup:

sybershot

Okay I got most of what I need to work, except one line of php.

$xml = simplexml_load_file('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$channel);

Anyone good with php, that might be able to help me?

you can view the code here within the page source http://www.scriptedintelligence.com/test/testor.html
and you can view the results here http://www.scriptedintelligence.com/test/testor.php


sybershot

I tried tutorial which is smaller in code but I still get errors
here is the short tutorial php version

<?php
$username 
"ScriptedIntell";
$feed "http://search.twitter.com/search.atom?q=from:" $username "&rpp=1";

function 
parse_feed($feed) {
    
$stepOne explode("<content type=\"html\">"$feed);
    
$stepTwo explode("</content>"$stepOne[1]);
    
$tweet $stepTwo[0];
$tweet htmlspecialchars_decode($tweet,ENT_QUOTES);
    return 
$tweet;
}

$twitterFeed file_get_contents($feed);
echo(
'&quot;'.parse_feed($twitterFeed).'&quot;');
?>


and here is where you can see the errors
http://www.scriptedintelligence.com/test/testor2.php

sybershot

#5
I found a viable solution, using a java widget, it works so I am pleased to a point for now. would like a php method for seo reasons though  :scratch-head:
my home page now displays my latest tweets ;D

DaveMorton

Your hosting provider has either configured PHP to run as CGI, or has altered the settings in the "common" php.ini file to disallow PHP's file functions to open URLs; or possibly even both. What this means, basically, is that PHP functions, such as file_get_contents() can only open files that exist within your "web space". There's no "direct" way around this, I'm afraid; at least, not with respect to the script that you're using. I've run into the same problem with the Program O project that I'm working on, for exactly the same reason. Let me see if I can dig up the code I used to open off-site RSS feeds, and I'll post it here.
Safe, Reliable Insanity, Since 1961!

DaveMorton

Ok, here's what I use currently. This function relies on the server's PHP library supporting cURL, but that describes over 90% of all PHP installs for web servers. If your hosting provider doesn't include cURL support with their PHP install, then you can probably ask them to include it.

Anyway, without further ado:


  function getRSS($feedURL) {
    $out = '';
    if (function_exists('curl_init')) {
      $ch = curl_init($feedURL);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      $data = curl_exec($ch);
      curl_close($ch);
      $rss = new SimpleXmlElement($data, LIBXML_NOCDATA);
      if($rss) {
        $items = $rss->channel->item;
        foreach ($items as $item) {
          $title = $item->title;
          $link = $item->link;
          $published_on = $item->pubDate;
          $description = $item->description;
          $out .= "<h3><a href=\"$link\">$title</a></h3>\n";
          $out .= "<p>$description</p>";
        }
      }
    }
    else $out = 'RSS Feed not available';
    return $out;
  }


Feel free (of course) to make whatever edits to the function code that you need to, to make this compatible with your site. And if you have any questions, just let me know. :)
Safe, Reliable Insanity, Since 1961!

Freddy

Nice one Dave.  Usually the bug bear for me is FSOCKET not being allowed and then I have to use CURL.  I've not had to do that for RSS, so I will pinch this too for the future. Cheers :)

sybershot

Thanks Dave, your wisdom is greatly appreciated. I really thought it my code that was the issue, it is nice to know it is not the case. not knowing php well or errors that follow sure can be daunting. I can't thank you enough in words for all your help.

just started learning php beyond copy and pasting and changing code to suit my needs, now I have to learn cURl  :'(  however It looks similar to php, so hopefully it should not be too hard  ;)

Thanks for the code I'll play around with it, and see if I can get it connect to my twitter account, and if my server provider supports it. From a quick look at your code, it looks like I just need to set some variables.


DaveMorton

Just yell if you get stuck, or have questions. One of my favorite things in life is helping others. :)
Safe, Reliable Insanity, Since 1961!

sybershot

I love helping others as well  :thumbsup: :thumbsup:
1 quick question is there a way trace

so I test what part works or where something might be broken or not working?

Flash as3 example:
trace($ch);

DaveMorton

Not really, but a tracing function could certainly be created. I just don't have enough time right now to make one. What I usually do is place the function into it's own PHP file, and use that file to test and refine the function until it does what I want it to, then migrate the function to it's "home". :)
Safe, Reliable Insanity, Since 1961!

Freddy

Or use an IDE with debugging features.  Something like NetBeans will do that kind of thing :

http://netbeans.org/index.html

Freddy