I am attempting to automate the sitemap.xml file on my site since the content is constantly changing. I currently open the file for appending: fopen($file_name, 'a');
so that I can add the new set of tags. However, I just noticed that the entire sitemap file has to be ended with a tag which means that every time I open the file, I need to append the text not to the end of the file, but to 1 line from the end.
So basically, how can I move the file pointer up after opening the file for appending so that I can achieve this? Thanks.
Update: here is what the sitemap looks like:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<url>
<loc>...</loc>
<lastmod>2009-08-23</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
so whenever I append, i need to add the <url>..</url>
part which must go right before the closing </urlset>
tag. I already have code that can append the xml to the end of the file. I just need to figure out how to append the new portion right before the closing tag.