elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Tutorial básico de Quickjs


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  php scritp para divivir archivo csv o txt
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: php scritp para divivir archivo csv o txt  (Leído 1,968 veces)
alexiscruz007

Desconectado Desconectado

Mensajes: 8


Ver Perfil
php scritp para divivir archivo csv o txt
« en: 23 Febrero 2015, 21:33 pm »

Tengo el siguiente codigo para dividir un archivo csv en partes mas chicas, pero el resultado de algunos sale desordenado, no se si es por que el archivo tiene un descripcion larga y tambien usa html y talvez lee algun carater de la archivo y se confunde, gracias de antemano por la ayuda.

Código
  1. <?php
  2. /**
  3. * Split a CSV file
  4. *
  5. * Each row is its own line.
  6. * Each cell is comma-separated
  7. * This file splits it into piece of size $size, add the header row
  8. * and names the resulting file filename_X.csv where filename is the
  9. * name of the original file and X is an incrementing integer.
  10. */
  11.  
  12. // Editable Options
  13. $size = 20000; // about 20kb
  14. $to_read = 'populate.csv';
  15.  
  16. // Do not edit
  17. $done = false;
  18. $part = 0;
  19. if (($handle = fopen($to_read, "r")) !== FALSE) {
  20.    $header = fgets($handle);
  21.    while ($done == false) {
  22.        $locA = ftell($handle); // gets the current location. START
  23.        fseek($handle, $size, SEEK_CUR); // jump the length of $size from current position
  24.        $tmp = fgets($handle); // read to the end of line. We want full lines
  25.        $locB = ftell($handle); // gets the current location. END
  26.        $span = ($locB - $locA);
  27.        fseek($handle, $locA, SEEK_SET); // jump to the START of this chunk
  28.        $chunk = fread($handle,$span); // read the chunk between START and END
  29.        file_put_contents($to_read.'_'.$part.'.csv',$header.$chunk);
  30.        $part++;
  31.        if (strlen($chunk) < $size) $done = true;
  32.    }
  33.    fclose($handle);
  34. }
  35. ?>

Mod: Etiquetas GeSHi obligatorias.


« Última modificación: 23 Febrero 2015, 22:44 pm por #!drvy » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ayuda con scritp en linux o batch
Scripting
guidosl 2 2,340 Último mensaje 15 Mayo 2010, 15:41 pm
por biribau
Scritp Perl para borrar archivos
Scripting
elecktra 3 5,854 Último mensaje 16 Agosto 2010, 05:21 am
por ~ Yoya ~
SQL Scritp en VS.NET 2008
.NET (C#, VB.NET, ASP)
striderwar 2 2,291 Último mensaje 7 Abril 2011, 19:49 pm
por [D4N93R]
como hago un scritp para que se instale los programas
Scripting
mcarrion 1 2,185 Último mensaje 25 Diciembre 2012, 09:40 am
por Eleкtro
php scritp para borrar las ultimas 5 lineas de un archivo csv o txt
PHP
alexiscruz007 1 5,459 Último mensaje 24 Febrero 2015, 03:41 am
por engel lex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines