1. php操作TXT文本,一个文本框,一个提交按钮,点击提交按钮之后,把这个文本框的内容写进data/
很简单,使用file_put_contents()函数
<?php
if(isset($_GET["name"])){
file_put_contents("data/text1.txt",$_GET["name"]);
}
?>
如果是post提交,就把$_GET修改成$_POST
2. PHP 修改文本文件内容
<?php
//从文件中读取
$path="1.txt";
$fp=file($path);
$arr=array();
foreach($fpas&$line){
$data=explode("=",$line);
if(count($data)>1)
{
$arr[]=array($data[0]=>$data[1]);
}else{
$arr[]=$line;
}
}
//假设要修改ProctType为10
setValue("ProctType","10",$arr);
//var_mp($arr);
//重新保存到文件
$fp=fopen("2.txt","w");
foreach($arras$row){
if(is_array($row)){
foreach($rowas$key=>$r){
fwrite($fp,$key."=".$r);
}
}else{
fwrite($fp,$row);
}
}
fclose($fp);
functionsetValue($name,$value,&$arr){
foreach($arras$key=>$row){
if(is_array($row)&&isset($row[$name])){
$arr[$key][$name]=$value;
//修改后记得加上换行
$arr[$key][$name]=$arr[$key][$name]." ";
}
}
}
?>
我测试了可以使用,如果可以请将两个问题都采纳下,谢谢。
3. 用PHP,怎么修改txt文本内的内容
<?php
header("Content-type:text/html;charset=gbk");
if(isset($_POST['submit'])){
$editContent=$_POST['editContent'];//获取输入框的内容
$res=file_put_contents("test.txt",$editContent);//执行修改
if($res){
echo'内容修改成功!';
}else{
echo'内容修改失败!';
}
}else{
echo'请做出修改....';
}
?>
<formmethod="post"action="">
<textareaname="editContent"cols="100"rows="15">
<?phpechofile_get_contents("test.txt")?>
</textarea>
<buttonname="submit">确认</button>
</form>
4. php高手进(关于php操作文本数据问题)
影响,那是毫无疑问的.
因为php读取文件时文件指针从前向后移动,直至访问到“\0"时才停止.
大的文件,小的文件读取方式都是一样,只是路径(文本长度)不一样.
所以花的时间也不一样.
花点钱升级下mysql吧不贵的,楼上说的access不通用,
可能虚拟空间不支持,也可能是在linux系统下.
注:文件存储信息(安全级别)非常不安全,谨用!!!
5. 如何使用PHP读取文本文件内容
利用PHP读取文本文件的内容,其实很简单,我们只需要掌握函数“file_get_contents();”的使用就可以了。下面,小编将作详细的介绍。
工具/原料
电脑一台
WAMP开发环境
方法/步骤
file_get_content()函数介绍。使用file_get_contents()获取txt文件的内容,具体参数说明如下:
2
具体实例说明。从文本文件tst.txt中读取里面的内容并显示在浏览器中,具体代码和图示如下:
<?php
$file = 'tst.txt';
$content = file_get_contents($file); //读取文件中的内容
echo $content;
?>
6. php如何读取文本指定的内容
php读取文件内容:
-----第一种方法-----fread()--------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str = fread($fp,filesize($file_path));//指定读取大小,这里把整个文件内容读取出来
echo $str = str_replace("\r\n","<br />",$str);
}
?>
--------第二种方法------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$str = file_get_contents($file_path);//将整个文件内容读入到一个字符串中
$str = str_replace("\r\n","<br />",$str);
echo $str;
}
?>
-----第三种方法------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str = "";
$buffer = 1024;//每次读取 1024 字节
while(!feof($fp)){//循环读取,直至读取完整个文件
$str .= fread($fp,$buffer);
}
$str = str_replace("\r\n","<br />",$str);
echo $str;
}
?>
-------第四种方法--------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$file_arr = file($file_path);
for($i=0;$i<count($file_arr);$i++){//逐行读取文件内容
echo $file_arr[$i]."<br />";
}
/*
foreach($file_arr as $value){
echo $value."<br />";
}*/
}
?>
----第五种方法--------------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str ="";
while(!feof($fp)){
$str .= fgets($fp);//逐行读取。如果fgets不写length参数,默认是读取1k。
}
$str = str_replace("\r\n","<br />",$str);
echo $str;
}
?>
7. php怎么把数据写入文本文件
php数据写入文本文件的具体操作步骤如下:
1、使用touch命令建立一个a.php的文件。
8. PHP操作txt,写入文本问题
不多说,手打上代码。我写的是php代码啊,不过php需要运行环境,但是js我不会
<?php
echo"<metacharset=utf-8> ";
$content='';
//生成静态文件代码
if(isset($_POST['btn'])){
if(!is_dir('data'))mkdir('data');
$file='data/text11.txt';//路径,可以自己修改
$content=$_POST['text'];
$fp=fopen($file,w);
fwrite($fp,$content);
fclose($fp);
echo"<scriptlanguage='javascript'> alert('写入成功') </script> ";
}
//下面是前台显示
$str="<formmethod='post'action=''> <inputtype='text'name='text'value='$content'> <inputtype='submit'name='btn'value='提交'> </form>";
echo$str;
?>
9. 如何在php中对文件进行读写操作
嗯,很简单,不过这次不是用file_put_contents()函数了,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
// 假设你的文件b.php已经创建,并且有权操作
// 但还是加上权限设定的语句,比较保险
chmod(dirname(__FILE__), 0777); // 以最高操作权限操作当前目录
// 打开b.php文件,这里采用的是a+,也可以用a,a+为可读可写,a为只写,如果b.php不能存在则会创建它
$file = fopen('b.php', 'a+'); // a模式就是一种追加模式,如果是w模式则会删除之前的内容再添加
// 获取需要写入的内容
$c = '我是要被追加的内容!';
// 写入追加的内容
fwrite($c, $file);
// 关闭b.php文件
fclose($file);
// 销毁文件资源句柄变量
unset($file);