fread/frwite curiousity

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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  


Re: fread/frwite curiousity

Shelly wrote:
Quoted text here. Click to load it

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>


Re: fread/frwite curiousity

Thanks, I'll try that.


Quoted text here. Click to load it

Re: fread/frwite curiousity

ltrim() didn't work.


Quoted text here. Click to load it

Site Timeline