Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default [PHP] RSSReader Class

    I just wrote my first ever class in PHP Classes are part of the idea of Object Based Programming (OBP). It just means that you can easily do something as many times as you need to - it is especially easy if you need to run functions again and again with the same parameters.

    The class that I wrote is a simple RSS reader. You just have to create the object, and then set the URL of the feed, and then run two functions. It is only compatible with PHP 5 and upwards - if you don't know if you fit this requirement make sure you run "$RSSReader->CheckVersion();". Here is the main coding, RSSReader.class.php:

    PHP Code:
    <?php
    // RSS Reader in PHP5
    // by Tim Rogers

    class RSSReader {
        var 
    $FeedURL;

        function 
    CheckVersion() {
            
    $yourphpversion phpversion();
            
    $comparison version_compare($yourphpversion'5.0.0');
            if (
    $comparison == -1) {
                die(
    "To use RSSReader, you need to upgrade to at least PHP5.");
            }
        }

        function 
    EchoChannel() {
            
    $_loadfeed simplexml_load_file($this->FeedURL);
            
    $channel_to_echo .= '<strong><u><a href="';
            
    $channel_to_echo .= $_loadfeed->channel->link;
            
    $channel_to_echo .= '">';
            
    $channel_to_echo .= $_loadfeed->channel->title;
            
    $channel_to_echo .= '</a></u></strong>';
            echo 
    $channel_to_echo;
        }

        function 
    EchoArticles() {
            
    $_loadfeed simplexml_load_file($this->FeedURL);
            foreach (
    $_loadfeed->channel->item as $item) {
              echo 
    "<a href='" $item->link "'>" $item->title "</a>";
            echo 
    "<br />";
              echo 
    $item->description;
            echo 
    "<br /><br />";
            }        
        }
    }
    ?>
    I expect, unless you have used classes before, which you likely haven't, you are confused now. You're probably asking how you use this! Well, here is my test.php:

    PHP Code:
    <?php
    // RSS Reader Class Test
    // by Tim Rogers

    // The script will fail unless the class can be loaded
    require("RSSReader.class.php");

    // Creates an "RSSReader" object
    $RSSReader = new RSSReader;
    // Checks your PHP version (not necessary)
    $RSSReader->CheckVersion();
    // Sets the URL of the feed you'd like to parse
    $RSSReader->FeedURL "http://www.habbo.co.uk/news/rss.xml";
    // Sends the feed title to the browser, linked to the homepage of the feed
    $RSSReader->EchoChannel();
    echo 
    "<br><br>";
    // Shows the articles, linked to their full story, with a short description
    $RSSReader->EchoArticles();
    ?>
    If you want to see it in action, visit http://php5.tim-rogers.co.uk/RSSReader/test.php5



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  2. #2
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Nice one Tim, very handy!

  3. #3
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default

    I guess that no one replies because they don't understand :p :big_grin:



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  4. #4
    Join Date
    Jan 2007
    Location
    West Yorkshire
    Posts
    384
    Tokens
    0

    Default

    I suppose thats very good for a first class, infact, it is. I might write my first today.

    BTW. It's OOP
    Last edited by ZAG; 15-02-2007 at 07:53 AM.

    “two players, two sides.
    one is light, one is dark.”
    - John Locke

  5. #5
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Th0m4s View Post
    I suppose thats very good for a first class, infact, it is. I might write my first today.

    BTW. It's OOP
    I just noticed that now It's Object Orientated Programming isn't it Post your class when you're done



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  6. #6
    Join Date
    Jan 2007
    Location
    West Yorkshire
    Posts
    384
    Tokens
    0

    Default

    I will do, probably wont do it until Ive come home from school.

    “two players, two sides.
    one is light, one is dark.”
    - John Locke

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •