這是我在一個網站地圖文件的末尾添加新條目代碼:PHP追加文本文件
$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);
其中一期工程正常的,但有時食堂了例如像在文件的結尾:
<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>
難道一個原因是PHP解析器無法正常到達文件的結尾?
可能重複( http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of-xml-file) – Gordon