Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 12 12311 ... LastLast
Results 1 to 15 of 173
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Angry Pulling Info From An RSS feed Using PHP? Help Needed Please.

    Hi All,

    I am growing increasingly fustrated with using php to pull out specific content from an RSS feed.

    I have managed to get all the info out but for some reason when i try to pull out specific bit of information it wont do it it returns nothing?

    here is the feed
    feed

    and here is my code:
    PHP Code:
    <?php require('_drawrating.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="stylesheet.css" />
    <link rel="stylesheet" type="text/css" href="css/rating.css" />

    <title></title>
    <style type="text/css">
    <!--
    a:link {
        color: #0066FF;
    }
    a:visited {
        color: #0066FF;
    }
    a:hover {
        color: #0000FF;
    }
    a:active {
        color: #0066FF;
    }
    -->
    </style></head>

    <?php
        
        define
    ("MAGPIE_INPUT_ENCODING""UTF-8");
        
    define("MAGPIE_OUTPUT_ENCODING""UTF-8");
        
    define("MAGPIE_CACHE_DIR""./magpierss/cache");
        
    define("MAGPIE_CACHE_ON"1);
        
    define("MAGPIE_CACHE_AGE"3600);
        include_once(
    "./magpierss/rss_fetch.inc");
        
    print 
    "<body>";



    $rss fetch_rss("http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D");
            
                    
    $loop_count 0;
                    for (
    $r 0$r <= $loop_count$r++) {
                    
                    foreach (
    $rss->items as $item){ 
                    if (
    $r <= $loop_count){
                    
    $href $item['link'];  
                    
    $title $item['title'];  
                    
    $desc $item['description'];  
                    
    $ref_date $item['pubdate'];
                    
    $content $item['atom_content'];
                     
                    print 
    "Full Content Of Feed Item";
                     
    //ORIGINAL
                    
    print "<div class='recommends'>";
                    print 
    $content;
                    print 
    "<br>";
                        
                    
    //MINE
                    
    print "My Attempt";
                    print 
    "<div class='recommends'>";
                    print 
    "<a href=$href>$title</a>";//Linked Title
                    
                    
    $r++;
                    print 
    "</div>";
        }
    }
        }
    ?>
    </body>
    </html>
    and "test" page from the above code
    page

    I am able to extract the title and the link but for some reason i cannot for the life of me get the image or the other info.

    i want to reduce the size of the font and maybe get rid of some of the text so that it fits into the box

    can anyone help me achieve this its doing my head in
    do i need to decode the feed first or something?

    i can provide some of the magpierss parser code if need be

    Many Thanks
    Luke

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    isn't it just a case of doing

    $cover= $item['coverArt'];

    <img scr="$cover" />

    I must admit to never having tried this though
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Try the code below.

    This the WHOLE code! No Magpie needed.
    PHP Code:
    <?php  
    // rss page  -  
    $feed_url "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

    // Load XML. 
    $xml=simplexml_load_file($feed_url);

    // How many items to display from the RSS Feed ...
    $count 5

    foreach (
    $xml->channel->item as $item) { 
    if(
    $count 0){ 
    echo

    <div style='font-family:arial; font-size:.8em;'>  
    <b>{$item->title}</b><br />
    {$item->description}<br />
    <a href='{$item->link}'>view it</a> 
    <br /><br /> 
    </div> 
    "
    ;  

    $count--; 
    }  
    ?>
    Some webhosts require PHP CURL method.
    If yours requires the use of CURL, let me know.

    EDIT:
    I forgot the image ... I'll get that and repost.


    .
    Last edited by mlseim; 12-08-2008 at 11:16 PM.

  • Users who have thanked mlseim for this post:

    LJackson (12-09-2008)

  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    just looked up my only code ever where i've used RSS

    basically its for grabbing the rss feed from those silly minicity sites and spitting out the latest happenings.

    Now its not linked to your problem obviously but perhaps you could reverse it so to speak

    PHP Code:
    echo "<span class='style1'><strong>Latest Happenings</strong></span>";
    echo 
    "<div align='left' class=\"style1\">";
    $site "http://".$cityname.".myminicity.com/rss";
    $fp = @fopen($site,"r");
    while(!
    feof($fp)) $raw .= @utf8_decode(fgets($fp4096));
    fclose($fp);

    if( 
    eregi("<item>(.*)</item>"$raw$rawitems ) ) {
     
    $items explode("<item>"$rawitems[0]);

     for( 
    $i 0$i count($items)-1$i++ ) {
      
    eregi("<title>(.*)</title>",$items[$i+1], $title );
      
    eregi("<url>(.*)</url>",$items[$i+1], $url );
      
    eregi("<categorie>(.*)</categorie>",$items[$i+1], $cat);
      echo 
    "<li>".$title[1].$cat[1];
     }

    echo 
    "</div>";}
    unlink($file);

    ?> 
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    Quote Originally Posted by hinch View Post
    isn't it just a case of doing

    $cover= $item['coverArt'];

    <img scr="$cover" />

    I must admit to never having tried this though
    Hi mateyeah i thought this also but for some odd reason it returns no value

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    Hi mlseim,

    this looks promising
    just need the picture and price and alls good

    cheers
    Luke

    p.s my webhost doesnt support Curl
    Last edited by LJackson; 12-08-2008 at 11:46 PM.

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Example of grabbing their own HTML code ... or parsing it out yourself.

    Because they have tags with colons "itms:coverArt" ... that refers to a "NameSpace URI",
    and requires some extra coding. Not sure how you want to display stuff, but it can
    be done several ways.

    The code now ...
    PHP Code:
    <?php  
    // rss page  -  
    $feed_url "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

    // Get XML
    $xml=simplexml_load_file($feed_url);

    // How many items to display from the RSS Feed ...
    $count 5


    foreach (
    $xml->channel->item as $item) { 
    if(
    $count 0){

    // Grabbing the NameSpace URI for "itms" and "content" ...
    $ns_itms $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
    $ns_content $item->children('http://purl.org/rss/1.0/modules/content/');

    echo
    "
    DISPLAYING THE PROVIDED HTML CONTENT ...<br />
    <div style='font-family:arial; font-size:.8em;'>
    {$ns_content}<br /><br />

    DISPLAYING THE INFO MANUALLY ...<br />
    <img src='{$ns_itms->coverArt}' /><br />
    {$item->content}<br />  
    <b>{$item->title}</b><br />
    {$item->description}<br />
    <a href='{$item->link}'>view it</a> 
    <br /><br />
    <hr>
    <br /><br /> 
    </div> 
    "
    ;  

    $count--; 
    }  
    ?>
    A working example of my code:
    http://www.cgrelayforlife.com/ipod.php
    Last edited by mlseim; 12-08-2008 at 11:58 PM.

  • Users who have thanked mlseim for this post:

    LJackson (12-09-2008)

  • #8
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    ahh I've finally noticed why its not a simple case of pulling out the coverArt field

    DOH

    its because its <itms:coverArt> not just <coverArt> like the title/link/description

    hrmp need to think about this then although my method above should work would just need to add in

    eregi("<itms:coverArt(.*)</url>",$items[$i+1], $art);

    echo $art;
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    WOW mlseim thats cool,

    i knew there must be a way to do it lol just didnt know how,

    im gonna have a play around with it to see if i can get a few more things out of the feed and add my own styling see how i get on,

    i will more thank likley be calling on you again for some help if you dont mind

    time to go and play around

    thanks so much for this guys i really appreciate it
    Luke

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    Quote Originally Posted by hinch View Post
    ahh I've finally noticed why its not a simple case of pulling out the coverArt field

    DOH

    its because its <itms:coverArt> not just <coverArt> like the title/link/description

    hrmp need to think about this then although my method above should work would just need to add in

    eregi("<itms:coverArt(.*)</url>",$items[$i+1], $art);

    echo $art;
    HI mate i inserted this code but didnt get any results, i replaced

    <itms:coverArt(.*)</url> with
    <itms:coverArt(.*)</itms:coverArt> and its displaying "array" instead of the pics?

    any ideas cheers mate.

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    mlseim,

    i have managed to get the genre but am unable to get the album and album price?

    also i am trying to get the image the same size as in the original feed but when i do it the image is distorted is there a way to do this so that the quality stays the same?

    here is how i resized the image size
    PHP Code:
    <a href='{$item->link}'><img src='{$ns_itms->coverArt}' height '100' width '100' border='0' /></a><br /> 
    cheers mate
    Luke

  • #12
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    They list the image 3 times, each one a different size.
    We're pulling the first one (unfortunately the smallest size).

    So, we'll have to do some fancy footwork to get the 3rd image.

    I'll experiment and get back on this.

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    My test site for the code below:
    http://www.cgrelayforlife.com/ipod.php
    (I didn't use the right charset (content-type), so my money symbol is weird)

    With a few tricks to alter the URL to the image ...
    PHP Code:
    <?php  
    // rss page  -  
    $feed_url "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=10/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

    // Get XML 
    $xml=simplexml_load_file($feed_url);

    // How many items to display from the RSS Feed ...
    $count 5

    foreach (
    $xml->channel->item as $item) { 
    if(
    $count 0){

    // Grabbing the NameSpace URI for "itms" and "content" ...
    $ns_itms $item->children('http://phobos.apple.com/rss/1.0/modules/itms/');
    $ns_content $item->children('http://purl.org/rss/1.0/modules/content/');

    // Trick the URL to grab the larger size image ...
    $photo=str_replace("53x53-50","100x100-75",$ns_itms->coverArt);

    echo
    "
    <img src='$photo' /><br />
    <b>{$ns_itms->album} - {$ns_itms->artist}</b><br />
    {$ns_itms->albumPrice}<br />
    <a href='{$item->link}'>view it</a><br />
    {$item->category} 
    <br /><br />
    <hr>
    <br /><br /> 
    </div> 
    "
    ;  

    $count--; 
    }  
    ?>
    Last edited by mlseim; 12-09-2008 at 01:25 AM.

  • Users who have thanked mlseim for this post:

    LJackson (12-09-2008)

  • #14
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    OMG thats awsome thank you so much for doing this

    will this method work for other rss feeds? is it a case of defining the child nodes and then the info?

    also what about caching, is there a way to make the page load faster? as i think when testing the page speed it was around 60seconds on 54kbs connection

    also mate what are you using to know what text to use to pull out the correct info like album price => albumPrice because im still using the magpierss parser text and the album price is all in small letters and wont work, so how are you finding out the correct text to use?

    cheers mate
    Luke
    Last edited by LJackson; 12-09-2008 at 11:29 AM.

  • #15
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    he's effectively loading them as 2 seperate rss feeds one containing the itms: section contents and one containing the main feed

    so $ns_itms->albumPrice is reading from the main feed (ns_itms) and pulling in the variable albumPrice from the sub feed and $item->category is pulling from the main feed

    it looks like $ns_content = $item->children('http://purl.org/rss/1.0/modules/content/'); is unused so can probably be commented out
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com


  •  
    Page 1 of 12 12311 ... LastLast

    Posting Permissions

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