...

View Full Version : Php to Csv



raposu
10-28-2012, 08:19 PM
Hello, I'm have this file in php


Categorias,26/10/2012 19:00,26/10/2012 20:00,26/10/2012 21:00,26/10/2012 22:00,26/10/2012 23:00,27/10/2012 00:00,27/10/2012 01:00,27/10/2012 02:00,27/10/2012 03:00,27/10/2012 04:00,27/10/2012 05:00,27/10/2012 06:00,27/10/2012 07:00,27/10/2012 08:00,27/10/2012 09:00,27/10/2012 10:00,27/10/2012 11:00,27/10/2012 12:00,27/10/2012 13:00,27/10/2012 14:00,27/10/2012 15:00,27/10/2012 16:00,27/10/2012 17:00,27/10/2012 18:00
Precipitacion,0.0,0.0,0.0,2.6,2.6,1.2,3.8,7.6,11.2,0.2,0.0,2.8,1.8,2.4,2.6,1.2,3.8,1.6,1.2,2.0,0.4,1 .8,0.2,0.
Temperatura,15.6,14.4,13.8,13.3,12.9,12.8,12.7,12.7,12.9,13.2,13.4,12.3,11.9,11.3,10.4,10.3,9.8,9.6, 10.2,9.6,9.6,8.5,8.5,8.1
Presion,962.6,963.2,963.6,963.8,963.9,964.1,964.2,964.4,965.1,965.7,966.0,967.0,968.3,969.4,970.8,97 2.5,973.4,974.5,975.1,975.3,975.9,976.3,977.0,977.8

I need the same file cloned, then use this script:


<?php
include("myfile.php"); // Conexion a nuestra BD

header("Content-type: application/csv");

$tutorial = strip_tags($cadena);

header("Content-Disposition: attachment; filename=NEW.csv\n");

header("Pragma: no-cache");
header("Expires: 0");
?>

but the result is not exact, contains the </ br>


Categorias,26/10/2012 18:00,26/10/2012 19:00,26/10/2012 20:00,26/10/2012 21:00,26/10/2012 22:00,26/10/2012 23:00,27/10/2012 00:00,27/10/2012 01:00,27/10/2012 02:00,27/10/2012 03:00,27/10/2012 04:00,27/10/2012 05:00,27/10/2012 06:00,27/10/2012 07:00,27/10/2012 08:00,27/10/2012 09:00,27/10/2012 10:00,27/10/2012 11:00,27/10/2012 12:00,27/10/2012 13:00,27/10/2012 14:00,27/10/2012 15:00,27/10/2012 16:00,27/10/2012 17:00<br/>Precipitacion,0.0,0.0,0.0,0.0,2.6,2.6,1.2,3.8,7.6,11.2,0.2,0.0,2.8,1.8,2.4,2.6,1.2,3.8,1.6,1.2,2.0,0 .4,1.8,0.2<br/>Temperatura,16.1,15.6,14.4,13.8,13.3,12.9,12.8,12.7,12.7,12.9,13.2,13.4,12.3,11.9,11.3,10.4,10.3,9.8 ,9.6,10.2,9.6,9.6,8.5,8.5<br/>Presion,962.3,962.6,963.2,963.6,963.8,963.9,964.1,964.2,964.4,965.1,965.7,966.0,967.0,968.3,969.4,97 0.8,972.5,973.4,974.5,975.1,975.3,975.9,976.3,977.0



You know how to remove that label?

bjarneo
10-29-2012, 02:46 PM
How about just use str_replace?


$str = 'Categorias,26/10/2012 18:00,26/10/2012 19:00,26/10/2012 20:00,26/10/2012 21:00,26/10/2012 22:00,26/10/2012 23:00,27/10/2012 00:00,27/10/2012 01:00,27/10/2012 02:00,27/10/2012 03:00,27/10/2012 04:00,27/10/2012 05:00,27/10/2012 06:00,27/10/2012 07:00,27/10/2012 08:00,27/10/2012 09:00,27/10/2012 10:00,27/10/2012 11:00,27/10/2012 12:00,27/10/2012 13:00,27/10/2012 14:00,27/10/2012 15:00,27/10/2012 16:00,27/10/2012 17:00<br/>Precipitacion,0.0,0.0,0.0,0.0,2.6,2.6,1.2,3.8,7.6,11.2,0.2,0.0,2.8,1.8,2.4,2.6,1.2,3.8,1.6,1.2,2.0, 0.4,1.8,0.2<br/>Temperatura,16.1,15.6,14.4,13.8,13.3,12.9,12.8,12.7,12.7,12.9,13.2,13.4,12.3,11.9,11.3,10.4,10.3,9. 8,9.6,10.2,9.6,9.6,8.5,8.5<br/>Presion,962.3,962.6,963.2,963.6,963.8,963.9,964.1,964.2,964.4,965.1,965.7,966.0,967.0,968.3,969.4,9 70.8,972.5,973.4,974.5,975.1,975.3,975.9,976.3,977.0';

$str = str_replace('<br />', '\n', $str);

echo $str;

Result:
Categorias,26/10/2012 18:00,26/10/2012 19:00,26/10/2012 20:00,26/10/2012 21:00,26/10/2012 22:00,26/10/2012 23:00,27/10/2012 00:00,27/10/2012 01:00,27/10/2012 02:00,27/10/2012 03:00,27/10/2012 04:00,27/10/2012 05:00,27/10/2012 06:00,27/10/2012 07:00,27/10/2012 08:00,27/10/2012 09:00,27/10/2012 10:00,27/10/2012 11:00,27/10/2012 12:00,27/10/2012 13:00,27/10/2012 14:00,27/10/2012 15:00,27/10/2012 16:00,27/10/2012 17:00
Precipitacion,0.0,0.0,0.0,0.0,2.6,2.6,1.2,3.8,7.6,11.2,0.2,0.0,2.8,1.8,2.4,2.6,1.2,3.8,1.6,1.2,2.0, 0.4,1.8,0.2
Temperatura,16.1,15.6,14.4,13.8,13.3,12.9,12.8,12.7,12.7,12.9,13.2,13.4,12.3,11.9,11.3,10.4,10.3,9. 8,9.6,10.2,9.6,9.6,8.5,8.5
Presion,962.3,962.6,963.2,963.6,963.8,963.9,964.1,964.2,964.4,965.1,965.7,966.0,967.0,968.3,969.4,9 70.8,972.5,973.4,974.5,975.1,975.3,975.9,976.3,977.0

raposu
10-29-2012, 05:11 PM
How about just use str_replace?


$str = 'Categorias,26/10/2012 18:00,26/10/2012 19:00,26/10/2012 20:00,26/10/2012 21:00,26/10/2012 22:00,26/10/2012 23:00,27/10/2012 00:00,27/10/2012 01:00,27/10/2012 02:00,27/10/2012 03:00,27/10/2012 04:00,27/10/2012 05:00,27/10/2012 06:00,27/10/2012 07:00,27/10/2012 08:00,27/10/2012 09:00,27/10/2012 10:00,27/10/2012 11:00,27/10/2012 12:00,27/10/2012 13:00,27/10/2012 14:00,27/10/2012 15:00,27/10/2012 16:00,27/10/2012 17:00<br/>Precipitacion,0.0,0.0,0.0,0.0,2.6,2.6,1.2,3.8,7.6,11.2,0.2,0.0,2.8,1.8,2.4,2.6,1.2,3.8,1.6,1.2,2.0, 0.4,1.8,0.2<br/>Temperatura,16.1,15.6,14.4,13.8,13.3,12.9,12.8,12.7,12.7,12.9,13.2,13.4,12.3,11.9,11.3,10.4,10.3,9. 8,9.6,10.2,9.6,9.6,8.5,8.5<br/>Presion,962.3,962.6,963.2,963.6,963.8,963.9,964.1,964.2,964.4,965.1,965.7,966.0,967.0,968.3,969.4,9 70.8,972.5,973.4,974.5,975.1,975.3,975.9,976.3,977.0';

$str = str_replace('<br />', '\n', $str);

echo $str;

Result:
Categorias,26/10/2012 18:00,26/10/2012 19:00,26/10/2012 20:00,26/10/2012 21:00,26/10/2012 22:00,26/10/2012 23:00,27/10/2012 00:00,27/10/2012 01:00,27/10/2012 02:00,27/10/2012 03:00,27/10/2012 04:00,27/10/2012 05:00,27/10/2012 06:00,27/10/2012 07:00,27/10/2012 08:00,27/10/2012 09:00,27/10/2012 10:00,27/10/2012 11:00,27/10/2012 12:00,27/10/2012 13:00,27/10/2012 14:00,27/10/2012 15:00,27/10/2012 16:00,27/10/2012 17:00
Precipitacion,0.0,0.0,0.0,0.0,2.6,2.6,1.2,3.8,7.6,11.2,0.2,0.0,2.8,1.8,2.4,2.6,1.2,3.8,1.6,1.2,2.0, 0.4,1.8,0.2
Temperatura,16.1,15.6,14.4,13.8,13.3,12.9,12.8,12.7,12.7,12.9,13.2,13.4,12.3,11.9,11.3,10.4,10.3,9. 8,9.6,10.2,9.6,9.6,8.5,8.5
Presion,962.3,962.6,963.2,963.6,963.8,963.9,964.1,964.2,964.4,965.1,965.7,966.0,967.0,968.3,969.4,9 70.8,972.5,973.4,974.5,975.1,975.3,975.9,976.3,977.0

Sorry, the numbers are always dynamic.

And other question .... you can download the csv file created in a directory on my server? (not in the database)

best regards

bjarneo
10-29-2012, 08:01 PM
Sorry, the numbers are always dynamic.

And other question .... you can download the csv file created in a directory on my server? (not in the database)

best regards


Yes, but in your csv script, just use str_replace before you print your output.

And yes, you can download the csv file created on your server.

raposu
10-29-2012, 09:51 PM
I appreciate very much your interest in helping me, but I find it insufficient, as my knowledge is very limited in php.

I auditioned a thousand ways with your code, but the result was always negative, probably not correctly applied, always write the file with tags.

regards

bjarneo
10-30-2012, 12:17 PM
Well, can you the code from 'myfile.php' ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum