Results 1 to 4 of 4

Thread: Simplepie Error handling

  1. #1
    Join Date
    Apr 2011
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default Simplepie Error handling

    Hello,

    I'm in need of some sort of an error handling script...
    My site fetches rss feeds from other sites (by using simplepie) and displays them like this: (http://netti-tv.net), but i'm having problems with one of the rss feeds, as some times the feed has no image -> my site crashes giving me this error code (http://netti-tv.net/katsomo):

    PHP Code:
    WarningInvalid argument supplied for foreach() in /home2/nettib22/public_html/katsomo.php on line 133

    Fatal error
    Call to a member function get_link() on a non-object in /home2/nettib22/public_html/katsomo.php on line 134 
    Lines 133-138:
    PHP Code:
            foreach($item->get_enclosures() as $enclosure);
            
    $i['img'] = str_replace("_m.jpg","_s.jpg" $enclosure->get_link());
            
            if(empty(
    $i['img'])){
            
    $i['img'] = 'img/noimage.png';
            } 
    I'm looking for a script that checks the rss feeds images and if there is no image it replaces it with "img/noimage.png".
    The above script works other vice but it has no error handling...

    Sorry for my bad English. I really hope somebody could help me as it's really annoying that my site crashes...I would really appreciate it.

    Edit: For now there is no error in http://netti-tv.net/katsomo but i'm still looking for the script. =/
    Last edited by X-Tream; 04-20-2013 at 02:36 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    PHP Code:
    # the first error is happening because foreach{} expects an array (or iterable object).
    # you need to make sure that's what you give it.
    # the second error is happening because of the first error.

    # try the method first
    $enclosures $item->get_enclosures();

    # see if it worked
    # (I'm assuming this get_enclosures method returns FALSE if it doesn't return an array.
    #  If that is not the case, you might need to use "if( is_array( $enclosures ) )" instead - 
    #  more correct, more accurate; but, if it works, doing "if( $enclosures )" is faster.
    if( $enclosures ){

    // foreach($item->get_enclosures() as $enclosure);
    # ALWAYS use brackets!
        # pass $enclosures to foreach{}
        
    foreach( $enclosures as $enclosure ){ //<-- important opening bracket

            # likewise, you might want to check if ::get_link() is returning a string as you expect
            
    $i['img'] = str_replace("_m.jpg","_s.jpg" $enclosure->get_link());

        }
    //<-- important closing bracket

    // end "if( $enclosures )"
         
    if(empty($i['img'])){
        
    $i['img'] = 'img/noimage.png';


  3. The Following User Says Thank You to traq For This Useful Post:

    X-Tream (04-20-2013)

  4. #3
    Join Date
    Apr 2011
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much for your help! It's working like a dream.

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    glad to hear it!

    If your question has been answered, please mark your thread "resolved":
    • On your original post (post #1), click [edit], then click [go advanced].
    • In the "thread prefix" box, select "Resolved".
    • Click [save changes].

  6. The Following User Says Thank You to traq For This Useful Post:

    X-Tream (04-20-2013)

Similar Threads

  1. help rssbox and "SimplePie" urgent!
    By atilaxp in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-31-2010, 05:02 PM
  2. AJAX CARS W/Simplepie
    By SpaceCowboy in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 08-28-2009, 01:23 PM
  3. Form Handling under SSL
    By Diversions in forum Looking for such a script or service
    Replies: 0
    Last Post: 04-25-2009, 01:43 PM
  4. MySQL Error Handling
    By Medyman in forum MySQL and other databases
    Replies: 6
    Last Post: 10-08-2007, 06:11 PM
  5. handling error messages in a url
    By tippex in forum JavaScript
    Replies: 3
    Last Post: 10-04-2006, 08:48 PM

Bookmarks

Posting Permissions

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