rahuul Posted March 24, 2010 Share Posted March 24, 2010 hi all i have a txt file which i want to edit on some condition. my code is as under <? $handle = fopen("keys/index.txt", "r+"); if ($handle) { $i=0; while (!feof($handle)) { print "hi<br>"; $cert = fgets($handle); $s=strpos($cert,"\t02",0); if($s){ $cert1 = str_replace("V","R",$cert); rewind($handle); fseek($handle,$i); fputs($handle, $cert1)or die("error"); print $i."<br>"; exit; } $i++; } fclose($handle); } print substr($cert,$s+1,2); ?> here i want to edit only one line if the line contain "\t02". i have user $i to count line no but after rewind how to come back to that line no. i used fseek but it moves pointer to that carector not on that line pls help............... thanks Link to comment https://forums.phpfreaks.com/topic/196346-editing-a-txt-file-in-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.