0

I've a text file.Now i want to replace text data with a form (POST or GET) in PHP. My text file like that-

"
Mr.A                         
87362                
Mr.B           
87427         
Mr.C          
85423
"

Now if i want to change Mr.A to Mr.H with a form submit POST or GET method,what should i do?

Fluffeh
  • 31,925
  • 16
  • 62
  • 77

2 Answers2

0

Whenever yo have to change a text file, you always have to read it into memory, do string manipulation and write the whole thing to a file again.

This explains a lot Overwrite Line in File with PHP

Assuming you can get your variables from your POST request, you should be able to follow the solution in the above link to help solve your problem.

Community
  • 1
  • 1
FaddishWorm
  • 5,278
  • 9
  • 32
  • 41
0

here is the code

  <?php  
  $n="filename.txt";
  $f=fopen($n,'r');
  $c=fread($f,100);
  $final = str_replace("Mr.A ", "Mr.".$_POST['field'], $c);
  fclose($f);
  $f=fopen($n,'w');
  fwrite($f,$final);
  fclose($f);
  ?>
Anoop
  • 963
  • 5
  • 16