Re: Problems with matrix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/22/07, Andres Rojas <a.rojas@xxxxxxxxxxx> wrote:
Hi all,

I'm new in PHP programming and I have a problem with this script. I need
to read a large file around 2Mb and several lines (28000). All start Ok,
but suddenly the script stop without message error.

<?php
       $fichero="62007lg.txt";
   $buffer = file($fichero);
   $lineas = count($buffer);

  foreach($buffer as $linea){

   list($day, $month, $year, $hour, $min, $temp, $hum, $dew, $baro,
$wind, $gust, $wdir, $rlastm, $rdai, $rmon, $ryear,
$heat)=sscanf($linea,"%d %d %d %d %d %f %d %f %f %d %d %d %f %f %f %f %f \n");

       $mday[]=$day;
       $mmonth[]=$month;
       $myear[]=$year;
       $mhour[]=$hour;
       $mmin[]=$min;
       $mtemp[]=$temp;
       $mhum[]=$hum;
       $mdew[]=$dew;
       $mbaro[]=$baro;
       $mwind[]=$wind;
       $mgust[]=$gust;
       $mwdir[]=$wdir;
       $mrlastm[]=$rlastm;
       $mdai[]=$rdai;
       $mrmon[]=$rmon;
       $mryear[]=$ryear;
       $mheat[]=$heat;
       echo"$day $month $year $hour $min $temp $hum $dew $baro $wind $gust
$wdir $rlastm $rdai $rmon $ryear $heat <br>";
       }

       ?>

If only I print the variable $buffer all it's ok, but when I try to fill
all the matrix the script doesn't work. If I reduce the number of matrix
only a 3 o 4 it's Ok, but If I increase number of this matrix the script
crash again.

Perhaps it's a problem of memory of server, but my  service provider say
me that this is not the problem.


Thank you very much

I don't know where the problem is, but I would use explode instead of
sscanf, so try if this code works:

<?php
      $fichero="62007lg.txt";
  $buffer = file($fichero,FILE_IGNORE_NEW_LINES); // Remove new lines in array
  $lineas = count($buffer);

 foreach($buffer as $linea){

      $array = explode(" ",$linea);

      $mday[]=$array[0];
      $mmonth[]=$array[1];
      $myear[]=$array[2];
      $mhour[]=$array[3];
      $mmin[]=$array[4];
      $mtemp[]=$array[5];
      $mhum[]=$array[6];
      $mdew[]=$array[7];
      $mbaro[]=$array[8];
      $mwind[]=$array[9];
      $mgust[]=$array[10];
      $mwdir[]=$array[11];
      $mrlastm[]=$array[12];
      $mdai[]=$array[13];
      $mrmon[]=$array[14];
      $mryear[]=$array[15];
      $mheat[]=$array[16];
      echo"$array[0] $array[1] $array[2] $array[3] $array[4]
$array[5] $array[6] $array[7] $array[8] $array[9] $array[10]
$array[11] $array[12] $array[13] $array[14] $array[15] $array[16]
<br>";
      }

      ?>

Tijnema

--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux