Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-28-2012, 08:19 PM   PM User | #1
raposu
New to the CF scene

 
Join Date: Oct 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
raposu is an unknown quantity at this point
Php to Csv

Hello, I'm have this file in php

Quote:
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:

Quote:
<?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>

Quote:
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
You know how to remove that label?
raposu is offline   Reply With Quote
Old 10-29-2012, 02:46 PM   PM User | #2
bjarneo
New Coder

 
Join Date: May 2012
Posts: 50
Thanks: 6
Thanked 4 Times in 4 Posts
bjarneo is an unknown quantity at this point
How about just use str_replace?
Code:
$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
bjarneo is offline   Reply With Quote
Old 10-29-2012, 05:11 PM   PM User | #3
raposu
New to the CF scene

 
Join Date: Oct 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
raposu is an unknown quantity at this point
Quote:
Originally Posted by bjarneo View Post
How about just use str_replace?
Code:
$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
raposu is offline   Reply With Quote
Old 10-29-2012, 08:01 PM   PM User | #4
bjarneo
New Coder

 
Join Date: May 2012
Posts: 50
Thanks: 6
Thanked 4 Times in 4 Posts
bjarneo is an unknown quantity at this point
Quote:
Originally Posted by raposu View Post
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.
bjarneo is offline   Reply With Quote
Old 10-29-2012, 09:51 PM   PM User | #5
raposu
New to the CF scene

 
Join Date: Oct 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
raposu is an unknown quantity at this point
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

Last edited by raposu; 10-30-2012 at 06:30 AM..
raposu is offline   Reply With Quote
Old 10-30-2012, 12:17 PM   PM User | #6
bjarneo
New Coder

 
Join Date: May 2012
Posts: 50
Thanks: 6
Thanked 4 Times in 4 Posts
bjarneo is an unknown quantity at this point
Well, can you the code from 'myfile.php' ?
bjarneo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:06 PM.


Advertisement
Log in to turn off these ads.