Uncaught Error: Call to a member function registerXPathNamespace() on boolean in

20 Views Asked by At

a couple of days ago this small script worked ok (API key removed)...

<?php

@$xml = simplexml_load_file('http://datapoint.metoffice.gov.uk/public/data/txt/wxfcs/regionalforecast/xml/');

$xml->registerXPathNamespace(

    "a", "www.metoffice.gov.uk/xml/metoRegionalFcst");

$paragraphs = $xml->xpath('//a:Paragraph');

$entry = 0;

$firstentry =2;  // select the entry number to start

$lastentry  =2;  // select the entry number to end

while (list( , $paragraph) = each($paragraphs)) {

  $entry++;

  if($entry >= $firstentry and $entry <= $lastentry) {

    echo '<p>', PHP_EOL;

     echo '<p style="text-align: left, color:white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;">', PHP_EOL;

    if ($paragraph['title'] != "Headline:")

        echo $paragraph['title'] , ' ';

    echo trim($paragraph), PHP_EOL;

    echo '</p>', PHP_EOL, PHP_EOL;

  }

}

?>

This is the xml it would "parse" not sure if thats the correct name for it

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<RegionalFcst xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst" createdOn="2024-03-14T01:22:14" issuedAt="2024-03-14T04:00:00" regionId="ee">
<FcstPeriods>
<Period id="day1to2">
<Paragraph title="Headline:">Dry morning with sunny spells. Showers for the afternoon.</Paragraph>
<Paragraph title="Today:">A dry morning with variable cloud and bright or sunny spells. Turning cloudier later in the afternoon, with bands of rain or showers, locally heavy, arriving from the west. Breezy and very mild. Maximum Temperature 16C.</Paragraph>
<Paragraph title="Tonight:">Often cloudy overnight with bands of showers, locally heavy, mainly in the south of the region. Drier towards the north with some clear spells. Breezy. Mild. Minimum Temperature 11C.</Paragraph>
<Paragraph title="Friday:">A mixture of sunny spells and showers, these locally heavy and perhaps thundery at times. Showers easing later. Breezy, especially on coasts. Mild. Maximum Temperature 15C.</Paragraph>
</Period>
<Period id="day3to5">
<Paragraph title="Outlook for Saturday to Monday:">A dry and bright day Saturday. Wet and breezy weather arrives overnight, clearing to showers on Sunday, with wind easing. Mostly dry and bright Monday. Temperatures mild or very mild.</Paragraph>
</Period>
<Period id="day6to15">
<Paragraph title="UK Outlook for Monday 18 Mar 2024 to Wednesday 27 Mar 2024:">Into the new week a continuation of the changeable but generally mild conditions looks likely. Rain heaviest in western, especially northwestern areas while parts of the south and southeast are likely to see longer, drier interludes. Winds generally light to moderate in the south and east, with stronger winds affecting north-western areas at times, although at this time nothing exceptional is expected. Into the latter part of next week and beyond we see a trend for temperatures to fall back closer to average across the UK. There is a small chance of more notable colder conditions developing, most probable across the north of the UK, but at this stage any confidence in this remains low.</Paragraph>
</Period>
<Period id="day16to30">
<Paragraph title="UK Outlook for Thursday 28 Mar 2024 to Thursday 11 Apr 2024:">For the end of March and into the start of April, pressure is likely to move to higher than average to the north of the UK. This pattern tends to push the focus of unsettled weather further south than usual, with highest rainfall most likely to be in the south of the UK. Conversely, northern areas tend to be drier compared to normal. Temperatures will probably be near average or slightly above overall, with any cooler interludes most likely in the north.</Paragraph>
</Period>
</FcstPeriods>
</RegionalFcst>

I have just noticed this morning that the script is not working and produces a error 500

This is the webpage where the formatted text should show.

Full disclosure, I have recently moved to a new dedicated server and i did transfer my domain over to namecheap. I didnt expect that to be the issue as it worked since the transfer(s).

Yours hopefully

Martin

0

There are 0 best solutions below