【发布时间】:2015-07-29 00:46:30
【问题描述】:
我是 PHP 新手。
我正在阅读 PHP 的基本核心概念。 '文件处理'是PHP的基本和重要概念之一。
在研究这个概念时,我遇到了 PHP 中可用的各种文件打开模式。以下是每种文件打开方式的说明:
Modes Description
r Open a file for read only. File pointer starts at the beginning of the file
w Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file
a Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist
x Creates a new file for write only. Returns FALSE and an error if file already exists
r+ Open a file for read/write. File pointer starts at the beginning of the file
w+ Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file
a+ Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist
x+ Creates a new file for read/write. Returns FALSE and an error if file already exists
我能够从上面的列表中理解前四种文件打开模式的目的(即“r”、“w”、“a”和“x”),但我完全无法理解上面列表中的其他文件打开模式(即“r+”、“w+”、“a+”和“x+”),因为它与前四种文件打开模式的描述相同。
所以我的问题是,既然前四种基本文件打开模式已经可用,那么为什么需要/定义这些额外的文件打开模式?使用它们的目的是什么?在处理文件时何时使用前四个以及何时使用后四个?
请帮助我解决我的上述疑问。 如果你能用一些合适的例子来解释,那对我和其他社区成员来说真的很棒并且很有帮助。
谢谢。
【问题讨论】:
-
你看不出“只读/只写”和“读/写”有什么区别吗?
-
我们在这个问题上有什么进展吗?
标签: php file file-io file-handling