Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP code to edit RSS file

  • 04-06-2007 11:18AM
    #1
    Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭


    Hi Lads,

    I'm slowly getting there with my flickr slideshow problem.

    I've discovered that google do a nice ajax feed api that takes in rss and creates a slideshow of it.

    My next problem is that flickr rss outputs the small version of the thumbnail

    EG
    <media:thumbnail url="http://farm1.static.flickr.com/214/499483509_84fdd2043b_s.jpg" height="75" width="75" />
    

    So what I want to do is to keep the rest of the rss and just edit the thumbnail section so it looks like this.
    <media:thumbnail url="http://farm1.static.flickr.com/214/499483509_84fdd2043b" />
    

    Is there a few simple commands that will do this for me?
    i.e.
    take in an html file
    replace - _s.jpg" height="75" width="75 with .jpg
    and just print the rest?

    Thanks for your help
    Gary

    P.S. Seems like a perl job but would like to do it in php


Comments

  • Closed Accounts Posts: 7,144 ✭✭✭DonkeyStyle \o/


    Here's a pretty basic example of str_replace() to get the ball rolling
    <?php
    $original_string = '<media:thumbnail url="http://farm1.static.flickr.com/214/499483509_84fdd2043b_s.jpg" height="75" width="75" />';
    $stuff_to_remove = '_s.jpg" height="75" width="75" />';
    $replace_with = '" />';
    $new_string = str_replace ($stuff_to_remove, $replace_with, $original_string);
    echo $new_string;
    ?>
    


  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    Thanks for that, ya I kinda get the string replace.

    I guess my problem is taking the data from an rss file and assigning it to a variable within php.

    i.e. something like

    $original_string = http://api.flickr.com/services/feeds/photos_public.gne?id=8115115@N08&format=rss_200


  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    Apologies to all I'm a lazy idiot:
    <?php
    
    $myFile = 'http://api.flickr.com/services/feeds/photos_public.gne?id=8115115@N08&format=rss_200';
    $content = file_get_contents($myFile);
    if ($content !== false) {
       $remove = '_s.jpg" height="75" width="75" />';
       $replace = '.jpg" />';
       $new_content = str_replace ($remove, $replace, $content);
       echo $new_content;
    } else {
      echo "Error";
    }
    
    ?>
    


Advertisement