Blogger Information
Blog 263
fans 3
comment 2
visits 113363
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
文件读写与创建
福哥的博客
Original
881 people have browsed it
<?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!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post