php如何写入文件
2010-10-19 13:12
232 查看
/*<html>
<head>
<title>
</title>
</head>
<body>*/
<?
if(isset($_POST['submitted'])){
if(!empty($_POST['quote'])&&($_POST['quote']!='Enter your quotion here.')){
if($fp = fopen('../quotex.txt','ab')){
//stream_encoding($fp,'utf-8');
fwrite($fp,"{$_POST['quote']}/n");
fclose($fp);
print"<p>Your quotation has been stored.</p>";
}else{
print '<p>style = "color:red;">Your quotation could not be stored due to a systeme error.</p>';
}
}else{
print '<p>style = "color:red:">Please enter a quotation!</p>';
}
}
?>
<form action = "add_quote.php" method = "post">
<textarea name = "quote" row = 5 cols = "30" >enter your quotation here.</textarea>
<input type = "submit" name = "submit" value = "Add the quote"/>
<input type = "hidden" name = "submitted" value = "true" />
</form>
</body>
</html>
摘抄自《php基础教程》
当文件不存在时,可以建立文件。
<head>
<title>
</title>
</head>
<body>*/
<?
if(isset($_POST['submitted'])){
if(!empty($_POST['quote'])&&($_POST['quote']!='Enter your quotion here.')){
if($fp = fopen('../quotex.txt','ab')){
//stream_encoding($fp,'utf-8');
fwrite($fp,"{$_POST['quote']}/n");
fclose($fp);
print"<p>Your quotation has been stored.</p>";
}else{
print '<p>style = "color:red;">Your quotation could not be stored due to a systeme error.</p>';
}
}else{
print '<p>style = "color:red:">Please enter a quotation!</p>';
}
}
?>
<form action = "add_quote.php" method = "post">
<textarea name = "quote" row = 5 cols = "30" >enter your quotation here.</textarea>
<input type = "submit" name = "submit" value = "Add the quote"/>
<input type = "hidden" name = "submitted" value = "true" />
</form>
</body>
</html>
摘抄自《php基础教程》
当文件不存在时,可以建立文件。
相关文章推荐
- PHP之如何将数组变量写入文件?
- php如何确保多个进程同时写入一个文件成功
- php在文件中写入回车问题,如何建立文本文件写入回车,记事本能看到
- 解析PHP中如何将数组变量写入文件
- PHP如何实现文件写入前追加,如依次写入"我 爱 你",而实现的效果是"你爱我"
- php如何向文件中写入换行
- 解析PHP中如何将数组变量写入文件
- php如何读取文件并写入数据库
- 解析PHP中如何将数组变量写入文件
- 如何将一个PHP数组有格式的写入文件中
- PHP如何把数据写入JSON文件并在另一PHP文件读取JSON数据?
- php 如何把中文写入json中 当json文件中还显示的是中文
- php如何读取文件并写入数据库
- 浅析php fwrite写入txt文件的时候用 \r\n不能换行的问题
- JAVA如何以追加的方式向文件中写入信息?
- php多个进程写入一个文件与模拟一个队列
- php 文件写入
- jmeter随笔 如何在写入jtl文件时同步写入数据库
- 多个线程同时写入一个文件问题------php
- 如何用PHP脚本和PEAR类创建ZIP档案文件