编辑txt文件php中的某些行

时间:2017-08-19 04:22:07

标签: php file text

我有一个配置文件,我在手机上编辑,而我不在家,只有一个文件。它有30行,但我只想编辑9-14行。最近我刚刚打开整个文件并查找行并进行编辑。想在移动设备上轻松一点。

你也可以在自己的文本框中拥有每一行吗?

 <?php
// set file to read
$filename = "ALLPAIRS-params.js";

$newdata = $_POST['newd'];

if ($newdata != '') {

// open file 
$fw = fopen($filename, 'w') or die('Could not open file!');
// write to file
// added stripslashes to $newdata
$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write 
to file');
// close file
fclose($fw);
}

// open file
  $fh = fopen($filename, "r") or die("Could not open file!");
// read file contents
  $data = fread($fh, filesize($filename)) or die("Could not read file!");
// close file
  fclose($fh);
// print file contents
 echo "<h3>Contents of File</h3>
<form action='$_SERVER[php_self]' method= 'post' >
<textarea name='newd' cols='100%' rows='50'> $data </textarea>
<input type='submit' value='Change'>
</form>";

?>

0 个答案:

没有答案