Skip to content

Instantly share code, notes, and snippets.

@josejailton
Created April 5, 2018 14:44
Show Gist options
  • Save josejailton/f664ca137ee155358c53db72c92c9761 to your computer and use it in GitHub Desktop.
Save josejailton/f664ca137ee155358c53db72c92c9761 to your computer and use it in GitHub Desktop.
$dom = new domDocument;
$dom->loadHTML($value);
$model['sefaz'] = array();
$array_sefaz_1 = array();
$array_sefaz_0 = array();
$tabelas = $dom->getElementsByTagName('table');
foreach($tabelas as $node){
if($node->nodeName=='table' && $node->getAttribute('class')=='toggle box' OR $node->getAttribute('class')=='toggable box'){
if($node->getAttribute('class')=='toggle box'){
foreach($node->childNodes as $child){
$cols = $child->getElementsByTagName('td');
echo $array_sefaz_0['numero_item'] = (int)$cols->item(0)->nodeValue;
echo "<br>".$array_sefaz_0['nome_produto'] = $cols->item(1)->nodeValue;
echo "<br>".$array_sefaz_0['quantidade'] = $cols->item(2)->nodeValue;
echo "<br>".$array_sefaz_0['unidade'] = $cols->item(3)->nodeValue;
//echo 'total linha: '.$cols->item(4)->nodeValue.'<br />';
}
}else{
if($node->getAttribute('class')=='toggable box'){
foreach($node->childNodes as $chil){
$cols = $chil->getElementsByTagName('span');
echo "<br>info2: ".$array_sefaz_1['codigo_cadastro_fabricante'] = $cols->item(0)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['ncm'] = $cols->item(1)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['cfop'] = $cols->item(4)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['ean'] = $cols->item(10)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['embalagem'] = $cols->item(11)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['quantidade'] = $cols->item(12)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['preco_unitario'] = $cols->item(16)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['ipi_valor'] = $cols->item(36)->nodeValue;
echo "<br>info2: ".$array_sefaz_1['ipi_percentual'] = $cols->item(38)->nodeValue;
}
}
echo '<br><br>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment