Bluehost.com Web Hosting $6.95

New line characters and carriage returns

This is a discussion on New line characters and carriage returns within the PHP General forums, part of the PHP Programming Forums category; Ok, don't know what I am doing wrong here...but for some reason I cannot get new line or ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-24-2003
Jonathan Villa
 
Posts: n/a
Default New line characters and carriage returns

Ok, don't know what I am doing wrong here...but for some reason I cannot
get new line or carriage return characters to work correctly...

For example,

When I send some emails, I try

$msg .= "From: me@mydomain.com\r\n
Content-Type: text/plain\r\n"

And it doesn't work correctly... the Content Type shows in my mail
body....


More importantly, I'm trying to write a system logger

$fileName = 'errors.'.date('dmY').'.log';
$error = date('h:i:s').' '.$script.' '.$error.'\n';
error_log ($error, 3, '/var/www/killerspin/logs/'.$fileName);

but the output into my log file shows the \n but does not use it.
Reply With Quote
  #2 (permalink)  
Old 10-24-2003
Jonathan Villa
 
Posts: n/a
Default Re: [PHP] New line characters and carriage returns

ok, I see, I have to use double quotes around it...

why is that?


On Fri, 2003-10-24 at 11:57, Jonathan Villa wrote:
> Ok, don't know what I am doing wrong here...but for some reason I cannot
> get new line or carriage return characters to work correctly...
>
> For example,
>
> When I send some emails, I try
>
> $msg .= "From: me@mydomain.com\r\n
> Content-Type: text/plain\r\n"
>
> And it doesn't work correctly... the Content Type shows in my mail
> body....
>
>
> More importantly, I'm trying to write a system logger
>
> $fileName = 'errors.'.date('dmY').'.log';
> $error = date('h:i:s').' '.$script.' '.$error.'\n';
> error_log ($error, 3, '/var/www/killerspin/logs/'.$fileName);
>
> but the output into my log file shows the \n but does not use it.

Reply With Quote
  #3 (permalink)  
Old 10-24-2003
Richard Baskett
 
Posts: n/a
Default Re: [PHP] New line characters and carriage returns

on 10/24/03 10:00, Jonathan Villa at jvilla@isdesigndev.com wrote:

> ok, I see, I have to use double quotes around it...
>
> why is that?


Because they actually have to be evaluated.. when they are in single quotes
php thinks they are the string \r\n and not newline or carriage returns that
they are when you use double quotes.. otherwise there would be no way of
echoing '\r\n' if php always thought they were newlines or carriage returns.

Cheers!

Rick

> On Fri, 2003-10-24 at 11:57, Jonathan Villa wrote:
>> Ok, don't know what I am doing wrong here...but for some reason I cannot
>> get new line or carriage return characters to work correctly...
>>
>> For example,
>>
>> When I send some emails, I try
>>
>> $msg .= "From: me@mydomain.com\r\n
>> Content-Type: text/plain\r\n"
>>
>> And it doesn't work correctly... the Content Type shows in my mail
>> body....
>>
>>
>> More importantly, I'm trying to write a system logger
>>
>> $fileName = 'errors.'.date('dmY').'.log';
>> $error = date('h:i:s').' '.$script.' '.$error.'\n';
>> error_log ($error, 3, '/var/www/killerspin/logs/'.$fileName);
>>
>> but the output into my log file shows the \n but does not use it.

Reply With Quote
  #4 (permalink)  
Old 10-24-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] New line characters and carriage returns

* Thus wrote Jonathan Villa (jvilla@isdesigndev.com):
> Ok, don't know what I am doing wrong here...but for some reason I cannot
> get new line or carriage return characters to work correctly...
>
> For example,
>
> When I send some emails, I try
>
> $msg .= "From: me@mydomain.com\r\n
> Content-Type: text/plain\r\n"
>


$msg .= "From: me@mydomain.com\r\nContent-Type: text/plain\r\n";

Your mail Program is seeing:
From: me@mydomain.com

Content-Type: text/plain


The empty line tells the program that it has reached the end of
headers.


Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
Reply With Quote
  #5 (permalink)  
Old 10-25-2003
James Moe
 
Posts: n/a
Default Re: New line characters and carriage returns

Jonathan Villa wrote:
>
> $msg .= "From: me@mydomain.com\r\n
> Content-Type: text/plain\r\n"
>

PHP is retaining the implicit linefeed in the text so there is a
blank line between From and Content-Type, the end-of-header indicator.
(You must have a dos-ish system.)
Change it to:
$msg .= "From: me@mydomain.com\r\n" . "Content-Type: text/plain\r\n";

>
> $fileName = 'errors.'.date('dmY').'.log';
>

The log files will sort a lot more sensibly if you use 'Ymd'.


--
jimoe at sohnen-moe dot com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:12 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0