I was hoping I could get some help with something I am struggling with. I parsing an XML feed with SimpleXML but, I am trying to remove the duplicates.
I have done a lot of research and can't seem to get this sorted. Best approach would be array_unique I think but, the variable $event
which contains the output from the parse doesn't seem to work with it.
Link to the script http://www.mesquiteweather.net/inc/inc-legend.php
Code I am using. Any help would be greatly appreciated. I have spent several days trying to resolve this.
// Lets parse the data
$entries = simplexml_load_file($data);
if(count($entries)):
//Registering NameSpace
$entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom');
$result = $entries->xpath("//prefix:entry");
foreach ($result as $entry):
$event = $entry->children("cap", true)->event;
endforeach;
endif;
// Lets creat some styles for the list
$legendStyle = "margin:10px auto 10px auto;";
$legend .= "<table style='$legendStyle' cellspacing='5px'>";
$legend .= "<tr>";
$i = 1;
foreach ($result as $entry) {
$event = $entry->children("cap", true)->event;
//Set the alert colors for the legend
include ('../inc-NWR-alert-colors.php');
$spanStyle = "background-color:{$alertColor};border:solid 1px #333;width:15px;height:10px;display:inline-block;'> </span><span style='font-size:12px;color:#555;";
$legend .= "<td> <span style='$spanStyle'> $event</span></td>";
if($i % 5 == 0)
$legend .= "</tr><tr>";
$i++;
}
$legend .= "</tr>";
$legend .= "</table>";
echo $legend;