Hola, file() te devuelve un array en el que cada elemento es una línea del archivo. Así que a continuación de eso lo que tendrías que hacer es iterar $csvxrow. Ejemplo:
Código PHP:
Ver original<?php
function csv_in_array($url,$delm=",",$encl="\"") {
$doc = new DOMDocument();
$xml2 = "A2CBOT.xml";
$doc->load($xml2);
$xp = new DOMXPath($doc);
$csvxrows = file($url); // ---- csv rows to array ---- foreach($csvrows as $csvrow) {
$csvxrow[0] = chop($csvxrow[0]); $keydata = explode($delm,$csvxrow[0]);
$anzdata = count($csvxrow); $z=0;
for($x=1; $x<$anzdata; $x++) {
$csvxrow[$x] = chop($csvxrow[$x]); $csv_data[$x] = explode($delm,$csvxrow[$x]); $i=0;
$a=0;
foreach($keydata as $key) {
$out[$z][$key] = $csv_data[$x][$i];
$i++;
////// Aqui reemplazara los atributos
foreach($xp->query('/ROOT/HEADER/@KEY[. != ""]') as $attrib)
{
$attrib->nodeValue = $out[$z][$key];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@AUFNR[. != ""]') as $attrib)
{
$attrib->nodeValue = $out[$z][$key];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GAMNG[. != ""]') as $attrib)
{
$attrib->nodeValue = $out[$z][$key];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GSTRS[. != ""]') as $attrib)
{
$attrib->nodeValue = $out[$z][$key];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GLTRS[. != ""]') as $attrib)
{
//$datesum = date($out[$z][$key], strtotime('+1 month'));
$attrib->nodeValue = $datesum;
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1AFFLL/E1FVOL/@MGVRG[. != ""]') as $attrib)
{
$attrib->nodeValue = $out[$z][$key];
}
//////
}
$z++;
}
}
echo $doc->saveXML();
return $out;
}
// --------------------------------------------------------------
?>
<?php
$csvdata = csv_in_array("LISTOTA.csv", ",", "\"");
Saludos.