Half,
Sorry about the messy code, first time posting. I have been a loaner until now.
Hmmm... not sure what data your referring to. The file I want to delete? If so it is a pdf. $it is just a number submitted from the html page when the user clicks on the delete button. Let's the script know what file to match to the db.
I did some more paying around, and I think you're right about the prob being the newline character. I just can't remove it. trim() or chop() only seem to hanlde white space.
any suggestions?
Thanks.
Code re-post so it is more readable
function delinf($f,$it,$rootPath,$addr) {
if (is_writable($f)) {
$fArray = file($f);
if (!$handle = fopen($f, 'w+')) {
print "Cannot open file ($f) for writing";
exit;
}
reset($fArray);
while (list($key,$item) = each($fArray)) {
if ($key == $it) {
$hol = strtok($item,"|");
$hol = strtok("|");
str_replace("\n","",$hol); //tried this instead of trim...didn't seem to work
$remove = $rootPath.$addr.$hol;
unlink($remove);
unset($fArray[$key]);
reset($fArray);
while (list($key,$item) = each($fArray)) {
$des = strtok($item,"|");
$fl = strtok("|");
if (!fwrite($handle,$des."|".$fl.$remove)) {
print "Cannot write to file ($f)";
exit;
}
}
}
}
fclose($handle);
rfile($f);
} else {
print "The file $g is not writable";
}
}
//end delete function