PHP是否具有检测正在运行的操作系统的功能? [英] Does PHP have a function to detect the OS it's running on?

查看:95
本文介绍了PHP是否具有检测正在运行的操作系统的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道要使用哪个关键字在PHP数据库中查找该关键字,所以我在这里询问.

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 new lines in textdocuments.

我在Windows中使用CSV文件,但是每次我想添加新行时,真正发生的是将新行粘贴到最新行的后面.

I'm using a CSV file in windows but each time I think I add a new line, what really happens is the new line gets pasted to the back of the latest line.

原因是,在Windows中,这是新行:\r\n 而我正在使用的CSVHandler.class.php文件仅添加\n

Reason is, in windows, a new line is this: \r\n And the CSVHandler.class.php file I'm using only adds \n

但是,在MAC OS X中,这是新行,与Windows不同.

However, in MAC OS X that's the new line, which is different from windows.

所以我正在寻找这个,所以我可以实现一个简单的if()语句并解决这个问题.目前,我已经对\r\n进行了硬编码,但是它应该更简单,不是吗?

So I'm looking for this so I can implement a simple if() statement and solve this. Currently I've hardcoded the \r\n, but it should be simpler, no?

推荐答案

PHP已包含常量

PHP has included the constant PHP_EOL for solving the problem you face, available since php 4.3.10 and PHP 5.0.2 - it contains a suitable end-of-line sequence for the server that PHP is running on.

如果要使用适合特定客户的其他行尾序列,则必须自己编写代码.确定客户端操作系统的一种方法是使用 get_browser ,您的服务器具有最新的 browscap.ini

If you want to use a different end-of-line sequence suitable for a particular client, then you'll have to code that yourself. One way to determine the client OS is to use get_browser, assuming your server has an up-to-date browscap.ini

这篇关于PHP是否具有检测正在运行的操作系统的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆