Array
(
)

PHP HELP - Salvando resultado obtido de um arquivo xml

PHP
Bruno
   - 30 set 2015


Citação:
Estou executando um comando que consulta um arquivo xml e me retorna um valor especifico, porém na hora de salva o valor salvo não é que nem o que mostra no navegador


Citação:
table.xml

#Código

<?xml version="1.0" encoding="UTF-8"?>
  <sensors totalcount="49" listend="1">
   <prtg-version>15.2.16.2230</prtg-version>
   <item>
    <downtimesince>353 d</downtimesince>
    <downtimesince_raw>000000030558881</downtimesince_raw>
    <device>4133-2 | BTZ5010035 |</device>
    <sensor>Fa0/0 - FastEthernet0/0</sensor>
    <lastvalue/>
    <status>Para baixo (confirmado) </status>
    <status_raw>13</status_raw>
    <message><div class="status">[[ Equipamentos desligados. (Confirmado em 28/09/2015 09:57:55 por Victor Giacometti Salomao (Indra)) ]]: No response (check: firewalls, routing, snmp settings of device, IPs, SNMP version, community, passwords etc) (erro de SNMP Nº -2003)<div class="moreicon"></div></div></message>
    <message_raw>[[ Equipamentos desligados. (Confirmado em 28/09/2015 09:57:55 por Victor Giacometti Salomao (Indra)) ]]: No response (check: firewalls, routing, snmp settings of device, IPs, SNMP version, community, passwords etc) (erro de SNMP Nº -2003)</message_raw>
    <priority>3</priority>
    <minigraph>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0|1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</minigraph>
    <checkbox><label class="tablecheckbox" for="18258"><input type="checkbox" name="objectid" id="18258" value="18258" status="13" class="checkbox tablemultiselectcheckbox tablemultiselectcheckboxunbind"></label></checkbox>
    <objid>18258</objid>
    <baselink>/sensor.htm?id=18258</baselink>
    <baselink_raw>18258</baselink_raw>
   </item>
   <item>
    <downtimesince>279 d</downtimesince>
    <downtimesince_raw>000000024186315</downtimesince_raw>
    <device>5004-10 | BSA 0750773 | 10.29.9.253</device>
    <sensor>Gi0/0 - 100 MBit/s</sensor>
    <lastvalue/>
    <status>Para baixo </status>
    <status_raw>5</status_raw>
    <message><div class="status">No response (check: firewalls, routing, snmp settings of device, IPs, SNMP version, community, passwords etc) (erro de SNMP Nº -2003)<div class="moreicon"></div></div></message>
    <message_raw>No response (check: firewalls, routing, snmp settings of device, IPs, SNMP version, community, passwords etc) (erro de SNMP Nº -2003)</message_raw>
    <priority>3</priority>
    <minigraph>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0|1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</minigraph>
    <checkbox><label class="tablecheckbox" for="59370"><input type="checkbox" name="objectid" id="59370" value="59370" status="5" class="checkbox tablemultiselectcheckbox tablemultiselectcheckboxunbind"></label></checkbox>
    <objid>59370</objid>
    <baselink>/sensor.htm?id=59370</baselink>
    <baselink_raw>59370</baselink_raw>
   </item>
   </sensors>


Citação:
Código php.

#Código
<?php 
//$arquivo = file_get_contents('table.xml');
$arquivo = file_get_contents('table.xml');

   $xml = new SimpleXMLElement($arquivo);

   foreach($xml as $item)
   {
      
      $device = utf8_decode($item -> device); 
	  $tags = utf8_decode($item -> tags);
           
//list($op, $cen) = explode(" ", $tags);
list($op, $cen) = array_pad(explode(' ',$tags), 2, '');
list($coop, $des, $ipsat) = array_pad(explode('|',$device), 3, '');

print "<br>". $coop;

}

 
?>

Bruno
   - 30 set 2015

Na tela ele me mostrar o seguinte resultado, exatamente como queria que fosse salvo em um arquivo.txt

4133-2
5004-10