Home Backend Development PHP Tutorial r n的研究解决方法

r n的研究解决方法

Jun 13, 2016 am 10:06 AM
enter quot return windows

\r \n的研究
因为在学习php,所以就发在这个区了。之所以这样写这个帖子,除了人云亦云外,还有高手没说明白,新手看不明白。
我就抛砖引玉了,因为我说还不一定正确。
\r \n所代表的含义是回车和换行,在一些情况下\r \n的效果是一样的,而回车和换行的意思大多数情况下也被认为是一样的,既然这样,何谈区别?
那么我们来了解他们的出处和本质含义。
出处是打印机
\r 含义 回车 英文全称carriage return,简称CR return是回的意思,carriage是车的意思,在打印机中,指(打字机等机器上的)滑动托架,很明显大家见过打印机就知道那个“车”只能左右移动,不能上下移动,那么回车的意思就是一行结束后回到初始位置。可是在电脑上很难描述了,用向左的方向键←移动到行最前端,就是这样效果。
\n 含义换行 英文全称 new line 或者line feed,feed这里是给,加的意思,在打印机中指再添加一行,因为carriage只能左右移动,那换行只能是打印纸来移动,相当于方向键↓的效果。

大家现在明白了吧,现在意义上的回车和换行还有键盘上的Enter其实是\r\n的效果(一下的回车换行均指\r\n的效果)。

可是在使用应该是有回车必有换行的,那么把效果统一起来的也是预料之中的事情,只是表达方式不一样而已,所以才有mac用\r,unix用\n,windows用\r\n
事实在windows记事本里这三种表达方式和用键盘回车键的效果是一样的,大约是windows已经自动转成\r\n了,但是用\n\r(颠倒顺序)\r \n(中间有空格)那么是起到了两次效果,但这不是绝对的,比如在unix看起来回车换行效果正常的文件放到windows记事本里就没有效果 但是会有小黑框,这个文件我用Dreamweaver打开是正常的。

另外据说\n还有含义指一个行的结束。其实和前面说的没区别嘛,这也许是Unix用它代表回车换行的原因。
还有软回车 硬回车的问题,这个在不同平台编软件可能会遇到,前面指\n 后者指\r\n。但我没经验去说是正确与否,但在Word中shift+enter软回车就是回车换行^l,enter硬回车是换段落^p,这个问题在网页设计中也会遇到。

------解决方案--------------------
windows \r\n
linux \n
mac \r

这是操作系统的约定,也可以说是历史遗留问题
知道了就可以,没有必要讨论
------解决方案--------------------

探讨
windows \r\n
linux \n
mac \r

这是操作系统的约定,也可以说是历史遗留问题
知道了就可以,没有必要讨论

------解决方案--------------------
好帖,实在的做点研究就是好的。
话说win系统下有个一溢出漏洞就是因为此类控制字引起的。

出发代码好像是这样的:

int main( void )

    { 

    for(;{
         printf( "hung up\t\t\b\b\b\b\b\b" );

         print("hung up\t\t\b\b\b\b\b\b";

        }

    return 0;

    }

忽略了退格前有制表符的情况导致内存越界覆盖。
------解决方案--------------------
探讨
windows \r\n
linux \n
mac \r

这是操作系统的约定,也可以说是历史遗留问题
知道了就可以,没有必要讨论
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

How to solve mysql cannot connect to local host How to solve mysql cannot connect to local host Apr 08, 2025 pm 02:24 PM

The MySQL connection may be due to the following reasons: MySQL service is not started, the firewall intercepts the connection, the port number is incorrect, the user name or password is incorrect, the listening address in my.cnf is improperly configured, etc. The troubleshooting steps include: 1. Check whether the MySQL service is running; 2. Adjust the firewall settings to allow MySQL to listen to port 3306; 3. Confirm that the port number is consistent with the actual port number; 4. Check whether the user name and password are correct; 5. Make sure the bind-address settings in my.cnf are correct.

MySQL can't be installed after downloading MySQL can't be installed after downloading Apr 08, 2025 am 11:24 AM

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.

Unable to access mysql from terminal Unable to access mysql from terminal Apr 08, 2025 pm 04:57 PM

Unable to access MySQL from the terminal may be due to: MySQL service not running; connection command error; insufficient permissions; firewall blocks connection; MySQL configuration file error.

How to copy and paste mysql How to copy and paste mysql Apr 08, 2025 pm 07:18 PM

Copy and paste in MySQL includes the following steps: select the data, copy with Ctrl C (Windows) or Cmd C (Mac); right-click at the target location, select Paste or use Ctrl V (Windows) or Cmd V (Mac); the copied data is inserted into the target location, or replace existing data (depending on whether the data already exists at the target location).

Solutions to the errors reported by MySQL on a specific system version Solutions to the errors reported by MySQL on a specific system version Apr 08, 2025 am 11:54 AM

The solution to MySQL installation error is: 1. Carefully check the system environment to ensure that the MySQL dependency library requirements are met. Different operating systems and version requirements are different; 2. Carefully read the error message and take corresponding measures according to prompts (such as missing library files or insufficient permissions), such as installing dependencies or using sudo commands; 3. If necessary, try to install the source code and carefully check the compilation log, but this requires a certain amount of Linux knowledge and experience. The key to ultimately solving the problem is to carefully check the system environment and error information, and refer to the official documents.

Can mysql run on Windows Can mysql run on Windows Apr 08, 2025 pm 01:54 PM

Running MySQL on Windows is feasible, but challenges such as port conflicts, permission issues, and environment variable settings need to be considered. Installation issues can be solved by customizing configuration files, adjusting user permissions, and setting environment variables correctly. Additionally, the appropriate storage engine should be selected, tweaked configuration files, and SSDs should be used to optimize performance.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

See all articles