/    Sign up×
Community /Pin to ProfileBookmark

I am writing to a file with append but the it adds it to the last line. Is there a new line command I can use?

Mr_Floppy

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@pyroAug 18.2003 — Yes, n is the new line character. (or, if you are working with an HTML file, it is, of course, <br>)
Copy linkTweet thisAlerts:
@Mr_FloppyauthorAug 18.2003 — I get this error when using "n"

"Warning: Unexpected character in input: '' (ASCII=92) state=1"

Mr_Floppy
Copy linkTweet thisAlerts:
@pyroAug 18.2003 — Let me see your full code, please.
Copy linkTweet thisAlerts:
@Mr_FloppyauthorAug 18.2003 — <?php

$date=date("F j, Y");

$fileloc="guests.txt";

$file=fopen($fileloc,"a") or die("Error. Please go back and try again");

fputs($file,n$name.":".$date.":".$comment);

fclose($file);

print "Thank you. Please go back.";

?>

Mr_Floppy
Copy linkTweet thisAlerts:
@Kr_ZAug 18.2003 — You have to change it to:

fputs($file,"n".$name.":".$date.":".$comment);
Copy linkTweet thisAlerts:
@Mr_FloppyauthorAug 18.2003 — That worked, thanks!

Mr_Floppy
Copy linkTweet thisAlerts:
@pyroAug 18.2003 — This might be easier...

fputs($file,"n$name:$date:$comment");

When using double quotes ("), variables will be read as the value of the variable. It's only with single quotes (') that it will display the actual variable.
×

Success!

Help @Mr_Floppy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...