下一篇 » « 上一篇

Figure 7-7: Writing and Reading from File

作者:semirock    时间:2008-03-07    来源:http://444p.com    点击:1685    本文共1篇文章 字体:[ ]

Figure 7-7: Writing and Reading from File

<HTML>
<HEAD>
<TITLE>Figure 7-7</TITLE>
</HEAD>
<BODY>
<?
/*
** open file for writing
*/
$myFile = fopen("file7-7.txt","w");

/*
** make sure the open was successful
*/
if(!($myFile))
{
print("Error: ");
print("'file7-7.txt' could not be created\n");
exit;
}


// write some lines to the file
fputs($myFile, "Save this line for later\n");
fputs($myFile, "Save this line too\n");

fclose($myFile); // close the file


/*
** open file for reading
*/
$myFile = fopen("file7-7.txt","r");

/*
** make sure the open was successful
*/
if(!($myFile))
{
print("Error:");
print("'file7-7.txt' could not be read\n");

本文来自 www.444p.com


exit;
}

while(!feof($myFile))
{
// read a line from the file
$myLine = fgets($myFile, 255);

print("$myLine <BR>\n");
}

fclose($myFile); // close the file

?>
</BODY>
</HTML>
责任编辑:semirock
发表评论
密码: (游客不需要密码)
记住我【Alt+S 或 Ctrl+Enter 快速提交】

搜索工具


《PHP函数》点击排行