Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从xml读取php_Php_Xml - Fatal编程技术网

从xml读取php

从xml读取php,php,xml,Php,Xml,我有一个来自url的数据点xml,该url的末尾有我的api键 因此,它不是以.xml结尾,而是以数字结尾 上周我一直试图理解xml,但我感到困惑 当有多个id时,理想情况下我希望下面的xml用php显示 当用作include时,我查看了简单的XML,但我很容易混淆:/ 我也尝试了这个,希望它能做我想要的,顺便说一句,我已经搜索过了 通过许多像这样的小脚本 我通过使用程序抓取xml进行编辑,并将其与.xml文件名和 上传到我的网站,就像我说的,我感到困惑: 我希望它看起来像这样 一些晴朗的天气会

我有一个来自url的数据点xml,该url的末尾有我的api键 因此,它不是以.xml结尾,而是以数字结尾

上周我一直试图理解xml,但我感到困惑 当有多个id时,理想情况下我希望下面的xml用php显示 当用作include时,我查看了简单的XML,但我很容易混淆:/

我也尝试了这个,希望它能做我想要的,顺便说一句,我已经搜索过了 通过许多像这样的小脚本

我通过使用程序抓取xml进行编辑,并将其与.xml文件名和 上传到我的网站,就像我说的,我感到困惑:

我希望它看起来像这样

一些晴朗的天气会在下午下雨

今天: 一些明亮或晴朗的天气,尤其是在该地区的东部,但下午更多的云层和零星降雨向东部扩散。最高温度12摄氏度

今晚: 任何一场雨都会很早就消散,给人一个干燥的夜晚,一些地方会有清晰的天气和一丝霜冻,尽管早晨云层会再次增加。最低温度0摄氏度

星期一: 干天气开始后,增厚的云层将在稍后从西部带来一些零星的降雨。然而,下午东部可能会出现一些较亮的天气。最高温度11摄氏度

周二至周四展望: 星期二天气干燥,有几阵阳光。周三早霜天气干燥明亮,但傍晚西部有雨。周四局部地区继续下雨

英国预测未来5天 今天东南部的云和雨正在消散。明天又湿又有风。 今天: 起初,整个苏格兰和北爱尔兰都是晴朗的天气,零星的阵雨。其他地区经常多云,威尔士和英格兰西北部的早雨缓慢向东南扩散,并逐渐减弱。西北风减弱,天气更加干燥、明亮

今晚: 一个干燥的夜晚,长时间的晴朗天气和微风使霜冻形成。在遥远的西部,天气越来越多云,黎明时有大雨和强风

星期一: 从东方开始,天气晴朗但寒冷。潮湿多风,有可能在北部和西北部刮大风。微风轻拂,南部雨势参差不齐

周二至周四展望: 星期二天气寒冷,随后大致晴朗干燥。周三和周四的天气变得更加不稳定,时而下雨,时而风力增强

2015年3月12日星期四至2015年3月21日星期六的英国展望: 由于锋面系统向东穿过英国,周四可能会有一些降雨影响大部分地区。西部有时会下大雨,也可能有强风。东部的雨可能会持续到周五,但随着高压预计的发展,情况会变得更加稳定。这给英国留下了很多干燥的天气和一些明亮或阳光充足的天气,尽管可能有大量的云层和零星的小雨或毛毛雨。这种情况看来将持续到下周。尽管有些寒冷的夜晚仍有可能出现,但风一般会很轻,气温接近一年中的平均值

2015年3月22日星期日至2015年4月5日星期日英国展望: 随着我们进入3月下旬,进入4月,高压很可能会逐渐减弱。这意味着北部地区很可能会变得更加不稳定,会有阵雨或更长时间的降雨。然而,再往南看,天气似乎会比平均水平更干燥,春天的阳光会更多。气温每天可能有很大的变化,白天温暖,夜晚寒冷

更新日期:2015年3月8日星期日0252

<RegionalFcst xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst" createdOn="2015-03-07T15:10:53" issuedAt="2015-03-07T16:00:00" regionId="ee">
<FcstPeriods>
<Period id="day1to2">
<Paragraph title="Headline:">Dry with increasing cloud. Mild although breezy.</Paragraph>
<Paragraph title="This Evening and Tonight:">
After a fine evening and clear start to the night cloud will thicken after midnight, though most parts will stay dry. Breezy winds will continue overnight. Minimum Temperature 5C.
</Paragraph>
<Paragraph title="Sunday:">
Generally cloudy with periods of rain and some brighter spells during the afternoon. Winds should ease and western parts may see a bright evening. Maximum Temperature 12C.
</Paragraph>
</Period>
<Period id="day3to5">
<Paragraph title="Outlook for Monday to Wednesday:">
Monday, a bright start but becoming windy with a spell of rain later. Tuesday should be fine with light winds. Wednesday starting fine but cloud thickening and wind strengthening later.
</Paragraph>
</Period>
<Period id="day6to15">
<Paragraph title="UK Outlook for Thursday 12 Mar 2015 to Saturday 21 Mar 2015:">
It is likely that some rain will affect most parts on Thursday as a frontal system tracks its way eastwards across the UK. The rain may be heavy at times in the west with strong winds also possible. The rain may linger in the east into Friday but things should then turn more settled as high pressure is expected to develop. This leaves a lot of dry weather over the UK with some bright or sunny spells though there may well be large amounts of cloud and the odd spot of mostly light rain or drizzle. This situation looks to persist into the following week. Winds should be generally light with temperatures close to average for the time of year, although some cold nights are still likely.
</Paragraph>
</Period>
<Period id="day16to30">
<Paragraph title="UK Outlook for Sunday 22 Mar 2015 to Sunday 5 Apr 2015:">
It is most probably that there will be a gradual weakening of the high pressure as we head through the latter part of March and into April. This means northern parts could well turn more unsettled, with showers or perhaps longer spells of rain. However, further south it looks like conditions are set to remain drier than average, with more spring sunshine. There is likely to be quite a large daily variation in temperatures, with warm days but chilly nights.
</Paragraph>
</Period>
</FcstPeriods>
</RegionalFcst>
希望你的

Bashy

您可以使用该方法从XML文件中获取所有段落元素,然后简单地循环结果:

// Load XML. Suppress warning on namespace not being absolute
@$xml = simplexml_load_file('metoforecast.xml');

// Create prefix for namespace
$xml->registerXPathNamespace(
    "a", "www.metoffice.gov.uk/xml/metoRegionalFcst"
);

// Get all Paragraph items from the XML
$paragraphs = $xml->xpath('//a:Paragraph');

// Loop through Paragraph items, displaying title and forecast
while (list( , $paragraph) = each($paragraphs)) {
    // Begin paragraph
    echo '<p>', PHP_EOL;

    // Display title unless headline
    if ($paragraph['title'] != "Headline:")
        echo $paragraph['title'] , ' ';

    // Display forecast for the day
    echo trim($paragraph), PHP_EOL;

    // End paragraph
    echo '</p>', PHP_EOL, PHP_EOL;
}

这太完美了,非常感谢你,我有一些xml文件,现在我有了一些工作,你是明星,再次感谢你!
<p>
    Dry with increasing cloud. Mild although breezy.
</p>

<p>
    This Evening and Tonight: After a fine evening and clear start to the night
    cloud will thicken after midnight, though most parts will stay dry. Breezy
    winds will continue overnight. Minimum Temperature 5C.
</p>

<p>
    Sunday: Generally cloudy with periods of rain and some brighter spells
    during the afternoon. Winds should ease and western parts may see a bright
    evening. Maximum Temperature 12C.
</p>

...