Error in XML import

Asked

Viewed 39 times

-2

When importing an electronic invoice XML file php has the following error:

Warning: Illegal string offset 'code' in C: xampp htdocs xmlparser output importNFe_output.php on line 127

Below PHP code

<?php

Linha

121   // Tag det dos itens unitarios:
121    $det=$doc->getElementsByTagName('det');
122    $itens="";
123    for ($i = 0; $i < $det->length; $i++) {
124    $item=$det->item($i);
125    $s="";
126    $s['codigo']=tagValue($item,"cProd");
127    $s['ean']=tagValue($item,"cEAN");
128    $s['nome']=tagValue($item,"xProd");
129    $s['ncm']=tagValue($item,"NCM");
130    $s['cfop']=tagValue($item,"CFOP");
131    $s['unidade']=tagValue($item,"uCom");
132    $s['quantidade']=tagValue($item,"qCom");
133    $s['valor']=tagValue($item,"vUnCom");
134    $s['valorTotal']=tagValue($item,"vProd");
135    $s['icms']=0;
136    $s['ipi']=0;
137    $itens[]=$s;
138        
139    }
140    $dados['itens']=$itens;
141    return($dados);

If anyone can shed a light.

1 answer

1

This declaring the variable $s as string, right after(line 126) trying to allocate as array

125    $s="";
126    $s['codigo']=tagValue($item,"cProd");

Declare the $s variable as an array

 $s = [];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.