(PHP 4 >= 4.3.2, PHP 5, PHP 7)
stream_wrapper_register — 注册一个用 PHP 类实现的 URL 封装协议
$protocol
, string $classname
[, int $flags = 0
] )
protocol待注册的封装的名字。
classname
实现了protocol的类名。
flags
Should be set to STREAM_IS_URL if
protocol is a URL protocol. Default is 0, local
stream.
成功时返回 TRUE, 或者在失败时返回 FALSE。
当 protocol 已经有处理者时,stream_wrapper_register() 将返回FALSE
| 版本 | 说明 |
|---|---|
| 5.2.4 |
添加 flags 参数.
|
Example #1 如何注册一个 stream wrapper
<?php
$existed = in_array("var", stream_get_wrappers());
if ($existed) {
stream_wrapper_unregister("var");
}
stream_wrapper_register("var", "VariableStream");
$myvar = "";
$fp = fopen("var://myvar", "r+");
fwrite($fp, "line1\n");
fwrite($fp, "line2\n");
fwrite($fp, "line3\n");
rewind($fp);
while (!feof($fp)) {
echo fgets($fp);
}
fclose($fp);
var_dump($myvar);
if ($existed) {
stream_wrapper_restore("var");
}
?>
以上例程会输出:
line1 line2 line3 string(18) "line1 line2 line3 "