Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Anyone sh*t hot with xml and php

422422 MVP
edited April 2012 in Vanilla 2.0 - 2.8

I am grabbing itunes api, and using simplexml to loop thru the xml page to grab songs, titles and...... Bloody images.

Struggling on the image bit, i need help asap. Can fire up private demo if you can help.

Email me at sales@vanillaskins.com cheers

There was an error rendering this rich post.

Best Answer

  • UnderDogUnderDog MVP
    edited April 2012 Answer ✓

    Did you look which information you get in $songinfo ? Are you sure there are 2 images sent? The smaller and the bigger one? if you use print_r($songinfo) you can see what the array contains. if you put it in between

    < pre >< /pre >

    tags you (hopefully) see a better readable array.

    If you want to work on the empty ul's and li's just let us know. It has also something to do with the arrays you get from simplexml and chart.xml

    There was an error rendering this rich post.

Answers

  • ToddTodd Vanilla Staff

    One thing to note that SimpleXml loads the entire file into memory. Not a big deal if the file is small, but if it's huge your script will die. I've had to use a combination of the XmlReader and SimpleXml to parse big files.

  • Yer read that it hogs memory and can crap itself, max xml file is 45kb. But as we cron it we will strip out all the crap, and rename to new xml file.

    Ive never played with xml, and so big learning curve

    There was an error rendering this rich post.

  • 422422 MVP
    edited April 2012

    Ok I fixed the main issue, which was grabbing the images.

    For some reason, within a ul li php loop, we are getting extraneous and empty lis, at the top of the list. Weird but will iron that out later.

    The issue now, is itunes xml gives you three image files per track, sized using php. But individually linked.

    So in my xml I have:

    http://a2.mzstatic.com/us/r1000/120/Music/86/80/3e/mzi.slypljfh.55x55-70.jpg
                    
    http://a1.mzstatic.com/us/r1000/120/Music/86/80/3e/mzi.slypljfh.60x60-50.jpg
                    
    http://a5.mzstatic.com/us/r1000/120/Music/86/80/3e/mzi.slypljfh.170x170-75.jpg
    

    In my php I have this:

    <?php  $mysongs = simplexml_load_file('charts.xml');
        echo "<div id='commentuser widget ringtonorama-1'><div class='widget'><ul class='vidselector' id=\"songlist\">\n";
        foreach ($mysongs as $songinfo):
            $name=$songinfo->name;
            $artist=$songinfo->artist;
            $releaseDate=$songinfo->releaseDate;
            $image=$songinfo->image;
            echo "<li>
                    <img class='minivideo-img' src=",$image,">
                    <h1><span=\"artist\">",$artist,"</span></h1>
                    <span class='minivideo-date'><span=\"releaseDate\">",$releaseDate,"</span></span>
                    <span class='minivideo-p'><span=\"name\">",$name,"</span></span>
                    </li>\n";
                    endforeach;
            echo "</ul></div></div>";
    ?>
    

    The issue is when the script loops thru it is grabbing the SMALLEST image, from the xml ( presumably default ) I just dont know how to tell php to grab the bigger one. the 175x175 version

    There was an error rendering this rich post.

  • Arggh frikken markdown. http://pastebin.com/7YsSEGX6

    There was an error rendering this rich post.

  • UnderDogUnderDog MVP
    edited April 2012 Answer ✓

    Did you look which information you get in $songinfo ? Are you sure there are 2 images sent? The smaller and the bigger one? if you use print_r($songinfo) you can see what the array contains. if you put it in between

    < pre >< /pre >

    tags you (hopefully) see a better readable array.

    If you want to work on the empty ul's and li's just let us know. It has also something to do with the arrays you get from simplexml and chart.xml

    There was an error rendering this rich post.

  • Cheers mate, sweet sorted it thankyou.

    There was an error rendering this rich post.

Sign In or Register to comment.