Jump to content

Writing text to a file...


evank3

Recommended Posts

I just found out my earlier problem of submiting info from a form to a file, but now I need it to add enters between words I enter so that they are on separate lines.  I have a simple form that submits to the file below and adds it to a blank text file:

[code]<?php
$word = $_REQUEST["word"] ;
$writedata = '$word';
$file = fopen("filter.txt", "a");
fwrite($file, $word);
fclose($file);
?>[/code]

When I submit it looks like Blah!Words but i want it like after I submit it.
Blah!
Words

Thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/28062-writing-text-to-a-file/
Share on other sites

Using
[code]<?php
$writedata = '$word\n';
?>[/code]

will put the characters '$' 'w' 'o' 'r' 'd' '\' 'n' into the file, it will [b]not[/b] put the value of the variable $word followed by a rewline into the file. To do that, you need:
[code]<?php
$writedata = $word . "\n";
?>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.