php rss - Posted In General Discussion


Welcome, Guest. Please login or register.
Username:   Password:

Hosted in the Cloud RSS

Recent Topics

Gallery Latest


81 Views
0 comment(s)

75 Views
0 comment(s)


189 Views
0 comment(s)

181 Views
1 comment(s)


406 Views
0 comment(s)

806 Views
0 comment(s)

Search The Gallery

User Info

Welcome, Guest. Please login or register.
August 19, 2018, 16:00:35 PM

Login with username, password and session length

Forum
Web
Gallery

Pages: [1] 2

php rss

Viewing: 0 Members and 1 Guest       Total Views: 4942

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

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.
Posted April 22, 2012, 01:44:13 AM Logged

Offline Freddy
United Kingdom WWW Administrator
Posts: 3450
Rank: Certified

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.
Posted April 22, 2012, 14:57:17 PM Logged

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

Thanks Freddy, I will give that a read thru in a bit  thumbsup
Posted April 22, 2012, 18:05:11 PM Logged

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

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

Code:
$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

Posted April 23, 2012, 00:06:50 AM Logged

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

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

Code:
<?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
Posted April 23, 2012, 00:52:56 AM Logged

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

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 Grin
Posted April 23, 2012, 01:45:57 AM
Last Edit: April 23, 2012, 02:21:13 AM by sybershot
Logged

Online DaveMorton
United States WWW Global Moderator
Posts: 2807
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

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.
Posted April 23, 2012, 05:42:59 AM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us

Online DaveMorton
United States WWW Global Moderator
Posts: 2807
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

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:

Code:
  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. Smiley
Posted April 23, 2012, 06:29:28 AM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us

Offline Freddy
United Kingdom WWW Administrator
Posts: 3450
Rank: Certified

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 Smiley
Posted April 23, 2012, 12:51:06 PM Logged

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

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  Cry  however It looks similar to php, so hopefully it should not be too hard  Wink

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.

Posted April 23, 2012, 16:41:52 PM Logged

Online DaveMorton
United States WWW Global Moderator
Posts: 2807
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

Just yell if you get stuck, or have questions. One of my favorite things in life is helping others. Smiley
Posted April 23, 2012, 16:43:38 PM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us

Offline sybershot Topic starter
United States WWW Posts: 1446
Rank: Certified

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);
Posted April 23, 2012, 17:23:03 PM Logged

Online DaveMorton
United States WWW Global Moderator
Posts: 2807
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

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". Smiley
Posted April 23, 2012, 17:56:35 PM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us

Offline Freddy
United Kingdom WWW Administrator
Posts: 3450
Rank: Certified

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

http://netbeans.org/index.html
Posted April 23, 2012, 18:46:45 PM Logged

Offline Freddy
United Kingdom WWW Administrator
Posts: 3450
Rank: Certified

And this is quite nice : http://www.php-debug.com/www/
Posted April 23, 2012, 18:50:19 PM Logged
General Discussion
Topic Pages: [1] 2
Jump to:  

Site Activity
Most Online Today: 192
164 Guests, 3 Users
Data, DaveMorton, Urania

fast-registration