[SOLVED] Deleting a line in a txt file
Posted: Mon Jan 17, 2005 10:23 am
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
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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';
?>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';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);