Solved

PHP: New line constant

Posted on 2009-05-12
2
1,207 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:hankknight
2 Comments
 
LVL 7

Expert Comment

by:Jonah11
Comment Utility
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
 
LVL 12

Accepted Solution

by:
alien109 earned 500 total points
Comment Utility
PHP_EOL
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now