SplFileObject::__construct() - 文件处理
SplFileObject::__construct()
(PHP 5 >= 5.1.0, PHP 7)
Construct a new file object
说明
publicSplFileObject::__construct(string $filename[,string $open_mode= "r"[,bool $use_include_path=FALSE
[,resource $context]]])Construct a new file object.
参数
$filenameThe file to read.
Tip如已启用fopen 包装器,在此函数中, URL 可作为文件名。关于如何指定文件名详见fopen()。各种wapper 的不同功能请参见支持的协议和封装协议,注意其用法及其可提供的预定义变量。
$open_modeThe mode in which to open the file. See fopen() for a list of allowed modes.
$use_include_pathWhether to search in the include_path for$filename.
$contextA valid context resource created with stream_context_create().
返回值
没有返回值。
错误/异常
Throws a RuntimeException if the$filenamecannot be opened.
Throws a LogicException if the$filenameis a directory.
范例
SplFileObject::__construct() example
This example opens the current file and iterates over its contents line by line.
以上例程的输出类似于:
Line 0 is
参见
- SplFileInfo::openFile() Gets an SplFileObject object for the file
fopen()
打开文件或者 URL
(PHP >= 5.3) If filename is a directory, a LogicException will be thrown: "Cannot use SplFileObject with directories"
When using URL as a filename, such as "http://..." or "php://stdin", and also have the fopen wappers on, and you get a 'RuntimeException' error, try using "NoRewindIterator" class to a SplFileObject instance. While opening a file, a rewind method will be called, but these URL iterators cannot be rewind, so you'll get a "Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot rewind file ...'" error.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!