Does PHP have a function to detect the OS it's running on?

后端 未结 13 2479
北荒
北荒 2021-02-14 17:00

I wouldn\'t know under what keyword to look for this in the PHP database, so I\'m asking here.

Reason I want to know is because of how different Operating Systems handle

13条回答
  •  一向
    一向 (楼主)
    2021-02-14 17:29

    Probably the safest thing to do when reading is to determine the line ending character(s) from the file itself, or accept all line endings interchangeably. This protects you from harm if you copy the csv file from one machine to another with a different OS. If you read before writing, you can make your output line endings match the line endings you identified when reading.

    For CSV files, php has some library functions. Try searching php.net for fgetcsv and fputcsv. There is the auto_detect_line_endings which can be set in the php.ini, but I don't know the specifics of how it works.

    I always use the "\n" by itself on both linux and windows. I use notepad to edit them in windows and it doesn't break the endings. For my own use of csv I find that it's too much hassle to support different endings, but if it's something users have to interact with then you want to be safe rather than convenient.

提交回复
热议问题