I am creating a text file from an array. I need a specific format with blank lines inserted between lines of data. I need "0D 0A 0D 0A", but all I am getting is "0A 0A".
My app is run on a windows xP platform.
Here is how I store the data in the array -
array_push($cData, array(
-
$aProject["Project_Name"],
-
$aProject["Point_Page1_Depth"],
-
$aProject["Water_Unit_Wt"],
-
$aProject["Coeff_of_Consol_Factor"],
-
$aProject["Name"],
-
$aProject["Datum"]));
-
-
//note the empty cell which in my previous language gave me 0D 0A, but in php only generates 0A
-
array_push($cData, array(""));
-
array_push($cData, array("**POINT"));
-
I steam out the data for download like this -
/*
-
-------------------------------------------------------
-
create handle for raw data file
-
-------------------------------------------------------
-
*/
-
$rawData = "c:/temp/test.csv";
-
-
/*
-
-------------------------------------------------------
-
look for file if found delete it because "into outfile"
-
will not overwrite existing file
-
-------------------------------------------------------
-
*/
-
$fh = fopen($rawData, 'w') or die("can't open file");
-
fclose($fh);
-
unlink($rawData);
-
-
/*
-
-------------------------------------------------------
-
open file using handle
-
-------------------------------------------------------
-
*/
-
$fh = fopen($rawData, 'w') or die("can't open file");
-
-
/*
-
-------------------------------------------------------
-
loop through main array $cData
-
and write each sub-array data to file as a line of data
-
then close input file.
-
-------------------------------------------------------
-
*/
-
foreach ($cData as $fields) {
-
fputcsv($fh, $fields);
-
}
-
-
fclose($fh);
-
-
/*
-
-------------------------------------------------------
-
create handle for gInt file
-
-------------------------------------------------------
-
*/
-
$outputFileName = 'gINT_upload.txt';
-
$fullOutputName = "c:/temp/".$outputFileName;
-
-
/*
-
-------------------------------------------------------
-
look for exiting output file, if found delete it.
-
-------------------------------------------------------
-
*/
-
$fh = fopen($fullOutputName, 'w') or die("can't open file");
-
fclose($fh);
-
unlink($fullOutputName);
-
-
/*
-
-------------------------------------------------------
-
create final output file
-
-------------------------------------------------------
-
*/
-
$fh = fopen($fullOutputName,"a+") or die("can't open file");
-
-
/*
-
-------------------------------------------------------
-
write into output file
-
-------------------------------------------------------
-
*/
-
fputs( $fh,rtrim(file_get_contents($rawData)) );
-
-
/*
-
-------------------------------------------------------
-
close output file
-
-------------------------------------------------------
-
*/
-
fclose($fh);
-
-
/*
-
-------------------------------------------------------
-
force download request to open on client.
-
-------------------------------------------------------
-
*/
-
if($result) {
-
header('Pragma: public');
-
header('Expires: 0');
-
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
-
header('Cache-Control: public');
-
header('Content-Description: File Transfer');
-
header('Content-Type: plain/text');
-
header('Content-Disposition: attachment; filename='.$outputFileName);
-
header('Content-Transfer-Encoding: ascii');
-
header('Content-Length: ' . filesize($fullOutputName));
-
-
@readfile($fullOutputName);
-
Well fputs( $fh, "\r\n" ); is the way I got it to work.
2 5975
I see my problem is "fputcsv($fh, $fields);" - this only adds 0a to the end of each line
whereas I can add 0a 0d with "fputs ($fh, "\r\n" );"
So the question becomes is there a way to add the "0d" with fputcsv?
The nice feature with fputcsv it it automatically adds delimiters around my text that contains commas.
Well fputs( $fh, "\r\n" ); is the way I got it to work.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rob Lemieux |
last post by:
Using Visual Basic 6.0
I want the program to be able to print the carriage return.
txtDisplay.Text = "Welcome to" + Chr(13) + "my demo."
All I get is
Welcome to|my demo.
|
by: gogomei |
last post by:
I have a text file like following and need to read out the names of each
person. Since the only accurate info is there is a null line before
starting a new name, I have written following code to...
|
by: Simon Middlemiss |
last post by:
I have a multiline textbox which I would like populated in the following
manner.
"Line1
Line2
Line3
Line4"
etc. I know how to do it in code, but is there a way to do it in the design
view?
|
by: Jason |
last post by:
hi, all,
after I read a string from a text file, which contains a hidden character
(carriage return) some where in the string, how can I remove this hidden
character, because when I populated it...
|
by: Michael McGarry |
last post by:
Hi,
I am reading strings from a text file using fscanf("%s", currToken);
This returns strings delimited by whitespace. How can I tell if the
string was followed by a carriage return in the...
|
by: John |
last post by:
I can create text file, but how can I create a text file where the values
are at the same location on every line?
I want to define the location where the values starts and define the length
of...
|
by: majidmajid |
last post by:
hay...i want to know how i can sort the records within text file...using c
|
by: nur123 |
last post by:
Thanks in advance who will look at it.
I have been encountering an issue which I can’t find a way out of it.
What my pgm does:
It (java codes) reads oracle table data and creates flat text...
|
by: evenlater |
last post by:
My db allows the user to send email via CDO. The body of the email is
determined in code. I have built an email form with To, CC and Subject
lines and a large text box for the body of the message...
|
by: cyuno |
last post by:
I am having problems in IE with the following text box javascript code. In Firefox the line breaks and carriage returns work perfectly but not in IE:
Here is the javascript:
function repp(){...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |