Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/12/2011, 21:39
starlightphp
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: ficheros y substrings

Al final decidí hacerlo a la aventura. Copio el código que quizás a alguien le sea útil en algún futuro =)
$Fichero = file("fichero.txt"); //Open the file
foreach ($Fichero as $i => $line){ //For each row read.....
Código PHP:
Ver original
  1. preg_match_all('/;/', $line, $Results, PREG_OFFSET_CAPTURE); //looking for ; contained in $line. This array is kept in $Results
  2.     //print_r($Results);
  3.     foreach($Results as $position){
  4.         $position[0] = $position[2][1]+1; //This is the start position for the date
  5.         $position[1] = $position[3][1]; //This is the end position for the date
  6.         $position[2] = $position[8][1]+1; //This is the position in which the balls start
  7.         $position[3] = $position[9][1]; //This is the position in which the balls ends
  8.         $position[4] = $position[10][1]+1; //This is the position in which the reintegro start
  9.         break;
  10.     }  
  11.     $size_date=$position[1]-$position[0]; //Max date size that we are going to substring
  12.     $size_balls=$position[3]-$position[2];  //Max balls size that we are going to substring
  13.     echo substr(strip_tags($line), $position[0], $size_date);
  14.     echo " ";
  15.     echo substr(strip_tags($line), $position[2], $size_balls);
  16.     echo " ";
  17.     echo substr(strip_tags($line), $position[4], 1);
  18.     echo '</br>';