
27/05/2009, 09:01
|
|
Respuesta: Escribir Array en Fichero CSV La solucion es la siguiente:
Código:
$separador=';'; //Los ficheros CSV tienen como separador ";"
//Open for reading and writing. Deletes content and overwrites the file.
$fichero=fopen($nombrefichero, "wb+");
$cabecera_fichero=array('REFERENCIA',$separador,'DESTINATARIO',$separador,'DOMICILIO',$separador,'POBLACION',$separador,'CODIGO POSTAL',$separador,'BULTOS',$separador,'PESO',$separador,'OBSERVACIONES',$separador);
if (is_writable($nombrefichero))
{
for($i = 0; $i < count($cabecera_fichero); $i ++)
{
//fwrite devuelve el numero de bytes escritos
$numbytes = fwrite ($fichero,$cabecera_fichero[$i]);
}
fwrite ($fichero,"\r\n"); //Salto de Linea
}
fclose($fichero); //Cerramos Fichero
|