473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

fread/frwite curiousity

I write to a file with fwrite. I do it with wordwrap (which I now think is
unnecessary). In the text area that it appears, it is left adjusted.
Anyway, the command is:

$message = wordwrap($_POST['Message'], 70);

where Message is the name of the text field.

Now when I go to read it, I use fread. The command is:

$message = fread($handle, 5000);

and I put in the text area of the read form:

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo wordwrap($message, 70); ?></textarea>

Here is the problem. There are about 15 spaces or so before the first bit
of text. After that, everything is fine. It wordwraps fine and does new
paragraphs. I cannot seem to find where those initial spaces entered the
picture.

Shelly

Jul 21 '05 #1
3 1554


Shelly wrote:
I write to a file with fwrite. I do it with wordwrap (which I now think is
unnecessary). In the text area that it appears, it is left adjusted.
Anyway, the command is:

$message = wordwrap($_POST['Message'], 70);

where Message is the name of the text field.

Now when I go to read it, I use fread. The command is:

$message = fread($handle, 5000);

and I put in the text area of the read form:

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo wordwrap($message, 70); ?></textarea>

Here is the problem. There are about 15 spaces or so before the first bit
of text. After that, everything is fine. It wordwraps fine and does new
paragraphs. I cannot seem to find where those initial spaces entered the
picture.


You're correct, you don't have to use wordwrap() before writing the
text to a file. You also don't have to use it when displaying the
message in the textarea. It will be automagically wrapped at the
correct places.

Please dump the incoming text at the start of your program, by adding
the following code:

echo '<pre>';print_r($_POST['Message']);echo '</pre>';

and see if the incoming text is correct.

If you still can't figure out where the extra spaces are coming from,
you can do use the ltrim() function to remove those spaces when
displaying the text.

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo ltrim($message); ?></textarea>

Ken

Jul 21 '05 #2
Thanks, I'll try that.

Shelly

"Ken Robinson" <ke******@rbnsn.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


Shelly wrote:
I write to a file with fwrite. I do it with wordwrap (which I now think
is
unnecessary). In the text area that it appears, it is left adjusted.
Anyway, the command is:

$message = wordwrap($_POST['Message'], 70);

where Message is the name of the text field.

Now when I go to read it, I use fread. The command is:

$message = fread($handle, 5000);

and I put in the text area of the read form:

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo wordwrap($message, 70); ?></textarea>

Here is the problem. There are about 15 spaces or so before the first
bit
of text. After that, everything is fine. It wordwraps fine and does new
paragraphs. I cannot seem to find where those initial spaces entered the
picture.


You're correct, you don't have to use wordwrap() before writing the
text to a file. You also don't have to use it when displaying the
message in the textarea. It will be automagically wrapped at the
correct places.

Please dump the incoming text at the start of your program, by adding
the following code:

echo '<pre>';print_r($_POST['Message']);echo '</pre>';

and see if the incoming text is correct.

If you still can't figure out where the extra spaces are coming from,
you can do use the ltrim() function to remove those spaces when
displaying the text.

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo ltrim($message); ?></textarea>

Ken

Jul 21 '05 #3
ltrim() didn't work.

Shelly
"Ken Robinson" <ke******@rbnsn.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


Shelly wrote:
I write to a file with fwrite. I do it with wordwrap (which I now think
is
unnecessary). In the text area that it appears, it is left adjusted.
Anyway, the command is:

$message = wordwrap($_POST['Message'], 70);

where Message is the name of the text field.

Now when I go to read it, I use fread. The command is:

$message = fread($handle, 5000);

and I put in the text area of the read form:

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo wordwrap($message, 70); ?></textarea>

Here is the problem. There are about 15 spaces or so before the first
bit
of text. After that, everything is fine. It wordwraps fine and does
new
paragraphs. I cannot seem to find where those initial spaces entered
the
picture.


You're correct, you don't have to use wordwrap() before writing the
text to a file. You also don't have to use it when displaying the
message in the textarea. It will be automagically wrapped at the
correct places.

Please dump the incoming text at the start of your program, by adding
the following code:

echo '<pre>';print_r($_POST['Message']);echo '</pre>';

and see if the incoming text is correct.

If you still can't figure out where the extra spaces are coming from,
you can do use the ltrim() function to remove those spaces when
displaying the text.

<textarea name="Message" cols="70" rows="15" readonly="readonly">
<?php echo ltrim($message); ?></textarea>

Ken


Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Luc Holland | last post by:
Hey, I'm working on a program that reads a binary file. It's opened with ==== if ((f1=fopen(argv,"rb"))==NULL) { fprintf(stderr,"Error opening %s for reading . . .\n",argv); exit(2); } ====...
10
by: Alain Lafon | last post by:
Helas, I got something that should be a minor problem, but anyhow it isn't to me right now. A little code fragment: fread(&file_qn, x, 1, fp_q); The corresponding text file looks like...
6
by: Patrice Kadionik | last post by:
Hi all, I want to make a brief comparison between read() and fread() (under a Linux OS). 1. Family read and Co: open, close, read, write, ioctl... 2. Family fread and Co: fopen, fclose,...
2
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
13
by: 010 010 | last post by:
I found this very odd and maybe someone can explain it to me. I was using fread to scan through a binary file and pull bytes out. In the middle of a while loop, for no reason that i could...
5
by: David Mathog | last post by:
When reading a binary input stream with fread() one can read N bytes in two ways : count=fread(buffer,1,N,fin); /* N bytes at a time */ or count=fread(buffer,N,1,fin); /* 1 buffer at a...
20
by: ericunfuk | last post by:
If fseek() always clears EOF, is there a way for me to fread() from an offset of a file and still be able to detect EOF?i.e. withouting using fseek(). I also need to seek to an offset in the file...
3
by: juleigha27 | last post by:
Hi, First off, I want to apologize if this already got posted it seemed like something happened when I tried to post it previously and it didn't work. I am new to file manipulation with c. I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.