Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/03/2014, 13:27
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Leer texto row por row.

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
  1. <?php
  2.  
  3. function csv_in_array($url,$delm=",",$encl="\"") {
  4.  
  5. $doc = new DOMDocument();
  6. $xml2 = "A2CBOT.xml";
  7. $doc->load($xml2);  
  8. $xp = new DOMXPath($doc);
  9.  
  10.     $csvxrows = file($url);   // ---- csv rows to array ----
  11.     foreach($csvrows as $csvrow) {
  12.      
  13.         $csvxrow[0] = chop($csvxrow[0]);
  14.         $csvxrow[0] = str_replace($encl,'',$csvxrow[0]);
  15.         $keydata = explode($delm,$csvxrow[0]);
  16.      
  17.         $anzdata = count($csvxrow);
  18.         $z=0;
  19.         for($x=1; $x<$anzdata; $x++) {
  20.             $csvxrow[$x] = chop($csvxrow[$x]);
  21.             $csvxrow[$x] = str_replace($encl,'',$csvxrow[$x]);
  22.             $csv_data[$x] = explode($delm,$csvxrow[$x]);
  23.             $i=0;
  24.             $a=0;
  25.             foreach($keydata as $key) {
  26.                 $out[$z][$key] = $csv_data[$x][$i];
  27.                 $i++;
  28.                 ////// Aqui reemplazara los atributos  
  29.    
  30.                    foreach($xp->query('/ROOT/HEADER/@KEY[. != ""]') as $attrib)
  31.                    {
  32.                     $attrib->nodeValue = $out[$z][$key];
  33.                    }
  34.                    foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@AUFNR[. != ""]') as $attrib)
  35.                    {
  36.                     $attrib->nodeValue = $out[$z][$key];
  37.                    }
  38.                    foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GAMNG[. != ""]') as $attrib)
  39.                    {
  40.                     $attrib->nodeValue = $out[$z][$key];
  41.                    }
  42.                    foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GSTRS[. != ""]') as $attrib)
  43.                    {
  44.                     $attrib->nodeValue = $out[$z][$key];
  45.                    }
  46.                    foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/@GLTRS[. != ""]') as $attrib)
  47.                    {
  48.                          
  49.                        //$datesum = date($out[$z][$key],  strtotime('+1 month'));
  50.                     $attrib->nodeValue = $datesum;
  51.                    }
  52.                    foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1AFFLL/E1FVOL/@MGVRG[. != ""]') as $attrib)
  53.                    {  
  54.                      $attrib->nodeValue = $out[$z][$key];
  55.                      }
  56.                 //////
  57.  
  58.                 }
  59.             $z++;
  60.             }
  61.     }    
  62.          
  63.    echo $doc->saveXML();  
  64.  
  65. return $out;
  66. }
  67.  
  68. // --------------------------------------------------------------
  69.  
  70. ?>
  71.  
  72. <?php
  73.  
  74. $csvdata = csv_in_array("LISTOTA.csv", ",", "\"");

Saludos.