基础
Last updated
Last updated
$handle = fopen('test.txt', 'wt');$handle = fopen('test.txt', 'rb');$handle = fopen("import.txt", "r");
echo fputs($handle ,'是否能写入?');$handle = fopen("import.txt", "r+");
echo fputs($handle ,'是否能写入?');$handle = fopen("import.txt", "w");
$content=fgets($handle);
var_dump($content);$handle = fopen("import.txt", "w+");
fputs($handle, '我写写!');
rewind($handle); //倒回文件指针的位置
$content=fgets($handle);
var_dump($content);//文件不能先存在,否则 fopen() 调用失败并返回 FALSE,并生成一条 E_WARNING 级别的错误信息
$handle = fopen("write.txt", "x");
var_dump($handle);<?php
//覆盖模式,不会清空已有的文件。
$handle = fopen("write.txt", "c");
fputs($handle, "1");
fseek($handle, 3);
fputs($handle, '2');fopen('php//stdout', 'w');file:// - 访问本地文件系统
http::// - 访问HTTP(s) 网址.
ftp:// 访问FTP(s) URLs
php:// - 访问各个输入/ 输出流(I/O streams)
zlib:// - 压缩流 :http://php.net/manual/zh/wrappers.compression.php$fp = fopen('php://stdout', 'w');
fputs($fp, 'hello world!');fputs(STDOUT, 'hello world!');$fp = fopen('php://stdin', 'r');
echo fgets($fp);echo fgets(STDIN);fputs(STDOUT, strtoupper(fgets(STDIN)));