0

i'm successfully managing to pull in the information in this feed:

http://api.zoopla.co.uk/api/v1/zed_index?area=yo1&output_type=outcode&api_key=XXXXMYAPIKEYGOESHEREXXXXX

I'm doing this with the following code:

<p><?php $postcode = get_the_title(); $str = urlencode($postcode); $url = "http://api.zoopla.co.uk/api/v1/zed_index?area=$str&output_type=outcode&api_key=5dj2d5x8kd2z2vnk9g52gpap"; $string = file_get_contents($url); echo $string;?></p>

However, this just echos the following output:

DE45 http://www.zoopla.co.uk/home-values/de45 53.258037 53.138911 -1.580861 -1.79776 England Derbyshire 53.198474 -1.6893105 DE45 368929 375424 362103 372926 333441 329349 322644 368056

How could i adapt my existing code to successfully echo individual elements from the feed, for example just the following fields wrapped in

tags:

zed_index zed_index_1year zed_index_2year

Thanks for your help!

dmt
  • 191
  • 2
  • 21
  • Please blank your *api_key*... and include an image instead – Anwar Aug 02 '16 at 15:12
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – ThW Aug 02 '16 at 20:55

1 Answers1

0

You could use simplexml_load_file() to get an array which will contains every of your XML tags :

<p>
    <?php
        $XML_url    =   'http://api.zoopla.co.uk/api/v1/zed_index?area=yo1&output_type=outcode&api_key=XXXXMYAPIKEYGOESHEREXXXXX';
        $XML_parsed =   simple_xml_load($XML_url);

        // print for debug
        echo '<pre>';
        print_r( $XML_parsed );
        echo '</pre>';  

        // Access one of the tag
        $tagName = $XML_parsed['tagName'];

        // Access a nested tag
        $nestedTag = $XML_parsed['first_tag']['second_tag'];
    ?>
</p>
Anwar
  • 4,162
  • 4
  • 41
  • 62