this is my code for adding a new entry at the end of a sitemap file:
$add_info="
<url>
$token
<lastmod>$date</lastmod>
</url>
</urlset>";
$end_string = "</urlset>";
$length_end_string = strlen($end_string);
fseek($handle, -$length_end_string, SEEK_END);
fwrite($handle, $add_info);
Which works alright but sometimes messes up the end of the file like for example:
<url>
<loc>http://example.com/url1.html</loc>
<lastmod>2011-08-31</lastmod>
</url>
</url<url>
<loc>http://example.com/url2.html</loc>
<lastmod>2011-08-28</lastmod>
</url>
</urls<url>
Could a reason for this be that php parser is unable to reach the end of file properly?