[SOLVED] Deleting a line in a txt file
Moderator: General Moderators
[SOLVED] Deleting a line in a txt file
Any one know how? I want to use the line as data for a query and then delete it after I'm done with it.
Thanks.
Chris
Thanks.
Chris
Last edited by siefkencp on Mon Jan 17, 2005 1:43 pm, edited 1 time in total.
Old code... (this works but too slow) and I took out the T and the O
Code: Select all
<?
include 'connect.php';
$number = 0;
$snumber = $number + 500;
$cbss_array = mysql_query ("SELECT `Lastname` , `Firstname` , `key` , `ZIP` FROM `cbss`")
or die ("Not Found1" . mysql_error());
while ($row_cbss = mysql_fetch_array($cbss_array, MYSQL_ASSOC)){
$lname_cbss = $row_cbssї'Lastname'];
$fname_cbss = $row_cbssї'Firstname'];
$key = $row_cbssї'key'];
$zip = $row_cbssї'ZIP'];
$nrccua_array = mysql_query ("SELECT * FROM `nrccua` WHERE `lname` = '$lname_cbss' and `Fname` = '$fname_cbss' and `zipcode` = '$zip'")
or die ("Not Found2" . mysql_error());
while ($row_nrccua = mysql_fetch_array($nrccua_array, MYSQL_ASSOC)){
$lname_nrccua = $row_nrccuaї'lname'];
$sequence = $row_nrccuaї'sequence'];
$number = $number + 1;
mysql_query ("INSER INT `dupe` (`sequence` , `cbsskey`) VALUES ('$sequence' , '$key')")
or die ("Not Found3" . mysql_error());
mysql_query ("DELET FROM `nrccua` WHERE `sequence` = '$sequence'")
or die ("Unsuccessful" . mysql_error());
print "$lname_cbss, $fname_cbss <br>\n";
if ($number == $snumber) {
print "<br><br><b>Deleted thes records from NRCCUA and inserteded the sequence number into NRCCUA_TEMP</b>";
die;
}
}
}
include 'close';
?>Working on this one:
I want to delete the line in the file after I'm done using it.
Remember there are obviously things I need to do to this one to make it ready...
I want to delete the line in the file after I'm done using it.
Remember there are obviously things I need to do to this one to make it ready...
Code: Select all
include 'connect.php';
$myFile = fopen("sequence.txt", "r");
$myFile_cbss = fopen("key.txt", "r");
$number = 0;
$snumber = $number + 500;
while (!feof($myFile) {
$line = fgets($myFile, 255);
$nrccua_array = mysql_query ("SELECT `sequence` FROM `nrccua` WHERE `sequence` = '$line'")
or die ("Not Found2" . mysql_error());
while ($row_nrccua = mysql_fetch_array($nrccua_array, MYSQL_ASSOC)){
$lname_nrccua = $row_nrccuaї'lname'];
$sequence = $row_nrccuaї'sequence'];
$number = $number + 1;
mysql_query ("INSER INTO `dupe` (`sequence` , `cbsskey`) VALUES ('$sequence' , '$key')")
or die ("Not Found3" . mysql_error());
mysql_query ("DELET FROM `nrccua` WHERE `sequence` = '$sequence'")
or die ("Unsuccessful" . mysql_error());
print "$lname_cbss, $fname_cbss <br>\n";
if ($number == $snumber) {
print "<br><br><b>Deleted thes records from NRCCUA and inserteded the sequence number into NRCCUA_TEMP</b>";
die;
}
}
}
include 'close';- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
here's the concept:
you can avoid the timeout via set_time_limit
Code: Select all
$lines = file('file.txt');
$copy = $lines;
foreach($lines as $ln => $line)
{
$line = trim($line);
// use the line in here
//...
//...
//...
// done using line
if( used )
unset($copyї$ln]);
}
$fp = fopen('file.txt','w');
fwrite($fp, join("\n",$copy));
fclose($fp);Different question this time... I'm close now... I just need to know how to read a line and ignore the return charicter my PHP manual tells me that fgets grabs the line plus the return...
Almoast there...
How about just using the file function as an array... I get the feeling you were heading there with your previous post...
Almoast there...
How about just using the file function as an array... I get the feeling you were heading there with your previous post...