[PHP] PHP EOL
Hello All, Happy pre independence for my American PHPers. And good health to all others. Have a quick question.. I have this code I use for the end of line characters used in my mailers. [Code] // Is the OS Windows or Mac or Linux if (strtoupper(substr(PHP_OS,0,5)=='WIN')) { $eol="\r\n"; } else if (strtoupper(substr(PHP_OS,0,5)=='MAC')) { $eol="\r"; } else { $eol="\n"; } [End Code] Does this suffice or should I be using the php supplied end of line? $eol=PHP_EOL; Or do these do the same thing? What advantages over the code I use does the PHP_EOL have? Or does it not matter with these and either are good to go? It seems to me that they do the same thing.. am I on the right track or missing something? Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" ? If their are, then I can see an advantage of using the PHP_EOL. Like I said, just a quick question. ;) Karl DeSaulniers Design Drumm http://designdrumm.com
Re: [PHP] PHP EOL
PHP_EOL is the best fit. you do not have to write multiple lines of code to do the same thing. ~viraj p.s. cross-posting is bad. removed db. from the cc list. On Sat, Jul 2, 2011 at 1:31 PM, Karl DeSaulniers wrote: > Hello All, > Happy pre independence for my American PHPers. And good health to all > others. > Have a quick question.. > > I have this code I use for the end of line characters used in my mailers. > > [Code] > // Is the OS Windows or Mac or Linux > if (strtoupper(substr(PHP_OS,0,5)=='WIN')) { > $eol="\r\n"; > } else if (strtoupper(substr(PHP_OS,0,5)=='MAC')) { > $eol="\r"; > } else { > $eol="\n"; > } > [End Code] > > Does this suffice or should I be using the php supplied end of line? > > $eol=PHP_EOL; > > Or do these do the same thing? > What advantages over the code I use does the PHP_EOL have? > Or does it not matter with these and either are good to go? > > It seems to me that they do the same thing.. am I on the right track or > missing something? > Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" ? > If their are, then I can see an advantage of using the PHP_EOL. > > Like I said, just a quick question. ;) > > > Karl DeSaulniers > Design Drumm > http://designdrumm.com > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP EOL
On Jul 2, 2011, at 3:10 AM, viraj wrote: PHP_EOL is the best fit. you do not have to write multiple lines of code to do the same thing. ~viraj p.s. cross-posting is bad. removed db. from the cc list. On Sat, Jul 2, 2011 at 1:31 PM, Karl DeSaulniers wrote: Hello All, Happy pre independence for my American PHPers. And good health to all others. Have a quick question.. I have this code I use for the end of line characters used in my mailers. [Code] // Is the OS Windows or Mac or Linux if (strtoupper(substr(PHP_OS,0,5)=='WIN')) { $eol="\r\n"; } else if (strtoupper(substr(PHP_OS,0,5)=='MAC')) { $eol="\r"; } else { $eol="\n"; } [End Code] Does this suffice or should I be using the php supplied end of line? $eol=PHP_EOL; Or do these do the same thing? What advantages over the code I use does the PHP_EOL have? Or does it not matter with these and either are good to go? It seems to me that they do the same thing.. am I on the right track or missing something? Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" ? If their are, then I can see an advantage of using the PHP_EOL. Like I said, just a quick question. ;) Karl DeSaulniers Design Drumm http://designdrumm.com Oops sory for the cross post. Didn't realize that's what that was. I have seen others do it in the past. I am a bit of a list novice. Wont happen again. Thanks for your reply. Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP EOL
On Sat, Jul 2, 2011 at 9:01 AM, Karl DeSaulniers wrote: > Hello All, > Happy pre independence for my American PHPers. And good health to all > others. > Have a quick question.. > > I have this code I use for the end of line characters used in my mailers. > > [Code] > // Is the OS Windows or Mac or Linux > if (strtoupper(substr(PHP_OS,0,5)**=='WIN')) { >$eol="\r\n"; > } else if (strtoupper(substr(PHP_OS,0,5)**=='MAC')) { >$eol="\r"; > } else { >$eol="\n"; > } > [End Code] > > Does this suffice or should I be using the php supplied end of line? > > $eol=PHP_EOL; > > Or do these do the same thing? > What advantages over the code I use does the PHP_EOL have? > Or does it not matter with these and either are good to go? > > It seems to me that they do the same thing.. am I on the right track or > missing something? > Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" > ? > If their are, then I can see an advantage of using the PHP_EOL. > > Like I said, just a quick question. ;) > When you say "mailers" are you talking about emails? If so then you should be using "\r\n" at all times since that's what numerous email-related RFCs specify. If you use anything else then you may find your email gets rejected by strictly implemented mail servers (rare these days, but it happens). Incidentally, CR only applies to Mac OS9 and earlier. OSX uses LF due to its BSD roots. For a near-complete list, see "Representations" here: http://en.wikipedia.org/wiki/Newline. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
[PHP] Re: [PHP-DB] PHP EOL
On Jul 2, 2011, at 3:01 AM, Karl DeSaulniers wrote: Hello All, Happy pre independence for my American PHPers. And good health to all others. Have a quick question.. I have this code I use for the end of line characters used in my mailers. [Code] // Is the OS Windows or Mac or Linux if (strtoupper(substr(PHP_OS,0,5)=='WIN')) { $eol="\r\n"; } else if (strtoupper(substr(PHP_OS,0,5)=='MAC')) { $eol="\r"; } else { $eol="\n"; } [End Code] Does this suffice or should I be using the php supplied end of line? $eol=PHP_EOL; Or do these do the same thing? What advantages over the code I use does the PHP_EOL have? Or does it not matter with these and either are good to go? It seems to me that they do the same thing.. am I on the right track or missing something? Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" ? If their are, then I can see an advantage of using the PHP_EOL. Like I said, just a quick question. ;) Karl DeSaulniers Design Drumm http://designdrumm.com What's interesting is that the SMTP standard actually requires a CRLF, even in unix-land, so PHP_EOL may not work as intended if you're using it there. From RFC-2821: 2.3.7 Lines SMTP commands and, unless altered by a service extension, message data, are transmitted in "lines". Lines consist of zero or more data characters terminated by the sequence ASCII character "CR" (hex value 0D) followed immediately by ASCII character "LF" (hex value 0A). This termination sequence is denoted as in this document. Conforming implementations MUST NOT recognize or generate any other character or character sequence as a line terminator. Limits MAY be imposed on line lengths by servers (see section 4.5.3). In addition, the appearance of "bare" "CR" or "LF" characters in text (i.e., either without the other) has a long history of causing problems in mail implementations and applications that use the mail system as a tool. SMTP client implementations MUST NOT transmit these characters except when they are intended as line terminators and then MUST, as indicated above, transmit them only as a sequence. The old sendmail operated this way. I believe more modern MTAs handle either CRLF, CR, or LF terminated lines on input, so in practice it may not matter. Also, as of OSX, Mac uses LF as the line terminator character, not CR, although I think it will handle either as a backwards compatibility feature. Elsewhere, such as in browser output, PHP_EOL is the best bet to cause a line termination outside of mail applications. In actual practice, however, PHP_EOL may be less useful than it would appear, as it only provides the appropriate line terminator based on the host it is running on. If your server is running a flavour of unix, and your running on windows, for example, the server will output '\n' to your browser, not '\r\n' as Windows would like. I believe all the modern browsers, regardless of platform OS, handle all three CRLF, CR, and LF and treat them as line terminators. However if you dump the return from the server to a file, you won't see this behaviour, obviously. There's a pretty long thread on this at stackoverflow.com: http://stackoverflow.com/questions/128560/when-do-i-use-the-php-constant-php-eol I tend to use PHP_EOL inplace of specifying a "\n" character string because to me it is clearer and more obvious what I mean, and does make the code at least a bit more portable. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-DB] Re: [PHP] PHP EOL
Thanks Stuart! Karl Sent from losPhone On Jul 2, 2011, at 8:45 AM, Stuart Dallas wrote: On Sat, Jul 2, 2011 at 9:01 AM, Karl DeSaulniers wrote: Hello All, Happy pre independence for my American PHPers. And good health to all others. Have a quick question.. I have this code I use for the end of line characters used in my mailers. [Code] // Is the OS Windows or Mac or Linux if (strtoupper(substr(PHP_OS,0,5)**=='WIN')) { $eol="\r\n"; } else if (strtoupper(substr(PHP_OS,0,5)**=='MAC')) { $eol="\r"; } else { $eol="\n"; } [End Code] Does this suffice or should I be using the php supplied end of line? $eol=PHP_EOL; Or do these do the same thing? What advantages over the code I use does the PHP_EOL have? Or does it not matter with these and either are good to go? It seems to me that they do the same thing.. am I on the right track or missing something? Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" ? If their are, then I can see an advantage of using the PHP_EOL. Like I said, just a quick question. ;) When you say "mailers" are you talking about emails? If so then you should be using "\r\n" at all times since that's what numerous email- related RFCs specify. If you use anything else then you may find your email gets rejected by strictly implemented mail servers (rare these days, but it happens). Incidentally, CR only applies to Mac OS9 and earlier. OSX uses LF due to its BSD roots. For a near-complete list, see "Representations" here: http://en.wikipedia.org/wiki/Newline. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP EOL
hi all, looking at the code Karl has posted, this code bit is not going to be a help in setting the 'new line' character in an email body, because it decides based on the server operating system. if (strtoupper(substr(PHP_OS,0,5)**=='WIN')) { >$eol="\r\n"; when sending out emails, the most compatible way is to use "\r\n" as Stuart has pointed out (plain text emails). ~viraj On Sat, Jul 2, 2011 at 7:15 PM, Stuart Dallas wrote: > On Sat, Jul 2, 2011 at 9:01 AM, Karl DeSaulniers wrote: > >> Hello All, >> Happy pre independence for my American PHPers. And good health to all >> others. >> Have a quick question.. >> >> I have this code I use for the end of line characters used in my mailers. >> >> [Code] >> // Is the OS Windows or Mac or Linux >> if (strtoupper(substr(PHP_OS,0,5)**=='WIN')) { >> $eol="\r\n"; >> } else if (strtoupper(substr(PHP_OS,0,5)**=='MAC')) { >> $eol="\r"; >> } else { >> $eol="\n"; >> } >> [End Code] >> >> Does this suffice or should I be using the php supplied end of line? >> >> $eol=PHP_EOL; >> >> Or do these do the same thing? >> What advantages over the code I use does the PHP_EOL have? >> Or does it not matter with these and either are good to go? >> >> It seems to me that they do the same thing.. am I on the right track or >> missing something? >> Is there any other OS's that are not WIN or MAC and use the "\r" or "\r\n" >> ? >> If their are, then I can see an advantage of using the PHP_EOL. >> >> Like I said, just a quick question. ;) >> > > When you say "mailers" are you talking about emails? If so then you should > be using "\r\n" at all times since that's what numerous email-related RFCs > specify. If you use anything else then you may find your email gets rejected > by strictly implemented mail servers (rare these days, but it happens). > > Incidentally, CR only applies to Mac OS9 and earlier. OSX uses LF due to its > BSD roots. For a near-complete list, see "Representations" here: > http://en.wikipedia.org/wiki/Newline. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php