hy
if i read a file with 500 lines, and if i want to replace text at the line 200 how can i do this ??? using fwrite()
thanks in advance
update text file
Moderator: General Moderators
Code: Select all
function replace_my_line($line, $new)
{
$line = 200; //if you define number of line with function call comment this line!
$file = "yourfile.txt";
$a = file("$file"); //first load txt file inty array
$new // holds your new text for line 200
$a[$line] = $new //replace the line 200 with your new content
$a = implode("", $a) //make a writable string (you cannot write array into txt file)
$handleTXT = fopen($file, "w");//open TXT file
fwrite($handleTXT, $a); //write the content to txt file
fclose($handleTXT); // close txt file...
}Code: Select all
replace_my_line($line, $new);
//$new is NEW content of a line
//$line is number of line in txt filethis should work
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Read through the PHP Manual on Filesystem.