「PHP Programming/Files」の版間の差分

→‎Line-endings: clarify line endings
(→‎Line-endings: clarify line endings)
Line-endings were mentioned briefly in the final example in the 'Reading' section of this chapter and it is important to be aware of them when working with files. When reading from a text file it is important to know what types of line-endings that file contains. 'Line-endings' are special characters that try to tell a program to display a new line. For example, Notepad will only move a piece of text to a new line if it finds "\r\n" just before the new line (it will also display new lines if you put word wrap on).
 
If someone writes a text file on a Windows system, the chances are that each line will end with "\r\n". Similarly, if they write the file on a Classic Macintosh (Mac OS 9 and under) system, each line will probably end with "\r". Finally, if they write the file on a Unix-based system (otherMac thanOS aX Macand GNU/Linux), each line will probably end with "\n".
 
Why is this important? Well, when you read a file into a string with [http://php.net/file_get_contents file_get_contents()], the string will be one long line with those line-endings all over the place. Sometimes they will get in the way of things you want to do with the string so you can remove them with:
匿名利用者