<?php
//write data
$f = fopen ('data.txt','w');
if($f){
fwrite($f,'Hello PHP');
fclose($f);
echo "ok";
}else{
echo '文件创建失败';
}
?>
<?php
//read data
$f = fopen ('data.txt','r');
$content = fgets($f);//fgets一次读取一行数据
echo $content;//第一行
echo fgets($f);//第二行
echo fgets($f);//第三行
fclose($f);
?>
<?php
//read循环处理,读取所有数据
$f = fopen ('data.txt','r');
while (!feof($f)){
$content = fgets($f);
echo $content;
}
fclose($f);
?>
<?php
//read data 最简单方式
echo file_get_contents('data.txt');
?>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!