I understand but onerror is client side, in order to delete something server-side when a client side trigger is run is to have it send a request back to the server with the necessary information to find the said div in the text file and then delete it.
For example you could add the following into your JS function that runs onerror
function ImgError(data) {
xmlhttp.open("POST","http://www.example.com/missing_image.php",false);
xmlhttp.send('src='+data.src);
data.src = 'http://www.example.com/missing_image.jpg";
}
Then in missing_image.php:
$src = isset($_POST['src']) ? $_POST['src'] : NULL;
if( is_null($src) ) exit;
$file = file_get_contents('divs.txt');
$pattern = '/<div[^>]+>\s<a[^>]+>\s<img src="'.preg_quote($src,'/').'"[^>]+>\s</a>\s</div>/';
if( preg_match($pattern,$file,$match) ) {
$newfile = str_replace($match[0],'',$file);
file_put_contents('divs.txt',$newfile);
}
Or something along those lines. Note that my regex pattern is untested and made in the quick reply window and may require tweaking to get it to work (or completely remade)