We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29181
    • 480 Posts
    Hi,
    I’ve been pottering around trying to add random quotes from the above webpage to my playground at www.flash-genie.de and this is what I’ve come up with, just in case someone is thinking about making something similar.

    I spent quite a bit of time looking for a XML parser type class that wasn’t too bulky. In the end I went for

    http://eric.pollmann.net/items/2007/2/2007_02_12_xmlparser/ which basically puts the XML convieniently into an array which even I can parse.

    I then created a snippet called getQuotes with:

    <?php
    require_once('assets/snippets/XMLparser/parseXML.php');
    $lang= (isset($lang))? $lang :"en";
    $parser = new XMLParser('http://quotes4all.net/xml/quotes.xml?language='.$lang.'&interval=0d&entries=1&encoding=UTF-8&imagesearchorder=author%2C%20default&dateformat=MM%2Fdd%2Fyyyy&timeformat=hh%3Amm%20a', 'url', 1);
    $tree = $parser->getTree();
    
    //All input is in the $tree multidimensional array
    //For anyone as new as me to PHP, if you want to output all the array dont use echo $tree because that won't work as you intend it to...
    // do print_r($tree)...which will do the trick, or even put it in a pre tag like:
    
      echo '<PRE>';
      print_r($tree);
      echo '</PRE>';
    
    ?>


    I added a lang variable so that I can call either language xml with a simple TV call in the snippet, along the lines of [!getQuotes?&lang=[*lang*]!]

    Obviously this could be used to parse any XML at all, hope it comes in handy for someone

    You can see the final version at www.flash-genie.de

    Cheers,
    Taff
      Adrian Lawley: www.adrianlawley.com
      • 10449
      • 956 Posts
      I would look into SimplePie: http://simplepie.org/
      Main reason being, it offers a cache-mechanism.
        • 27376
        • 576 Posts
        You might want to check out ApoXX’s FeedX snippet.