evank3 Posted November 22, 2006 Share Posted November 22, 2006 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!WordsThanks in advance Link to comment https://forums.phpfreaks.com/topic/28062-writing-text-to-a-file/ Share on other sites More sharing options...
Vikas Jayna Posted November 22, 2006 Share Posted November 22, 2006 replace the line[code]$writedata = '$word';[/code]with[code]$writedata = '$word\n';[/code] Link to comment https://forums.phpfreaks.com/topic/28062-writing-text-to-a-file/#findComment-128400 Share on other sites More sharing options...
kenrbnsn Posted November 22, 2006 Share Posted November 22, 2006 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 Link to comment https://forums.phpfreaks.com/topic/28062-writing-text-to-a-file/#findComment-128778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.