PHP: New line constant

Is there a constant or something that I can use for a OS compatible new line?

Something that will automatically use \n for Linux and \r for Windows?
LVL 16
hankknightAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
alien109Connect With a Mentor Commented:
PHP_EOL
0
 
Jonah11Commented:
I don't know if there is a built-in constant, but one approach would be to make a custom function.  psuedo code:



function mycr() {
 
  $os = php_uname('s');//get the os
  //process the returned value to something standard, ie, change anything containing "Win" to "WINDOWS" or some such
 
  //now branch off that
  if ($os == "Linux")
     return "\n"
  else if ($os == "Windows")
     return "\r"
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.