By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,041 Members | 1,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,041 IT Pros & Developers. It's quick & easy.

adding a new line character in a string.

P: 2
Hi friends

I need to write s string into a log file a string each time I run my php script.

How could I write the details into a new line each time I run.

I tried using \n but it is not working.....
eg:
$logdetail= "date: ".$todate.$count."values inserted\n";
fwrite($fptr, $logdetail);

THIS IS VERY URGENT Friends
Feb 1 '07 #1
Share this Question
Share on Google+
3 Replies


Motoma
Expert 2.5K+
P: 3,235
Hi friends

I need to write s string into a log file a string each time I run my php script.

How could I write the details into a new line each time I run.

I tried using \n but it is not working.....
eg:
$logdetail= "date: ".$todate.$count."values inserted\n";
fwrite($fptr, $logdetail);

THIS IS VERY URGENT Friends
Welcome to The Scripts!
Did you use fopen()?
Feb 1 '07 #2

Atli
Expert 5K+
P: 5,058
Hi.

If your using windows you should do "\r\n" instead of "\n".

[PHP]$fh = fopen($filename, "a");
fwrite("I am a new line :D \r\n");
fclose($fh);[/PHP]
Feb 1 '07 #3

P: 2
for adding a new line caharacter in a string, concatenate the string with a \n enclosed in double quotes.
eg: $string="new employee"."\n";
fwrite($fptr, $string);
This will write the contents of the string '$string' in to the file and take the cursor to the next line of the file.
So, when you execute the foll: code,
$emp_name="John";
fwrite($fptr, $emp_name);
The name John will be printed in the next line of the file.

i.e. new employee
John
Feb 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.