[英]Echo XML Elements with file_get_contents
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 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 DE45 http://www.zoopla.co.uk/home-values/de45 53.258037 53.138911 -1.580861 -1.79776英格兰德比郡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 zed_indexzed_index_1年zed_index_2年
Thanks for your help! 谢谢你的帮助!
You could use simplexml_load_file()
to get an array which will contains every of your XML tags : 您可以使用simplexml_load_file()
获得一个包含每个XML标签的数组:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.