I have a strange problem, my code loads a file into an array, then it changes the array, makes another array and finally the are merged and saved to the file but the strange thing is that the code always adds an empty line to the old lines like this:
...
the newest lines...
the newset lines...
older lines...
older lines...
very old lines...
very old lines...
...
if you know what I mean 🙂 finally the file is full of empty lines. Here is the code:
{
$xmlf = file('guestbook.xml');
// delete the first two lines
unset($xmlf[0]);
unset($xmlf[1]);
$varxml = array ('<?xml version="1.0"?>');
$varxml[1]= '<guestbook>';
$varxml[2]= '<entry>';
$varxml[3]= "<name>".$name."</name>";
$varxml[4]= "<date>".date("F d, Y")." - ".date("h:i:s A")."</date>";
$varxml[5]= "<ip>".$REMOTE_HOST."</ip>";
$varxml[6]= "<webpage>".$homepage."</webpage>";
$varxml[7]= "<email>".$email."</email>";
$varxml[8]= "<home>".$home."</home>";
$varxml[9]= "<message>".$text."</message>";
$varxml[10]= '</entry>';
$varxml2 = array_merge($varxml, $xmlf);
$comma_separated = implode("\r", $varxml2);
$fh = fopen('guestbook.xml', "wb");
fputs($fh, $comma_separated);
fclose($fh);
}