error on line 1 at column 6: XML declaration allowed only at the start of the document


This page contains the following errors:

error on line 1 at column 6: XML declaration allowed only at the start of the document

Below is a rendering of the page up to the first error.

--------------------------------------------------------------------------------------------------

今天調試接口的時候又發現了這個東西,在Google上找來幾篇stackoverflow的帖子,總算是解決了。一般出現這種情況的時候

首先應該注意的是在“Header('Content-type: text/xml');”前不要有其他輸出,最好將“Header('Content-type: text/xml');”放在文件的最頂端;

然后檢查一下是不是真的像它說的那樣在輸出的第一行有空行;

最后就是檢查你的編碼是不是BOM格式的,如果是的話,改成無BOM格式的試試。

什么是BOM,其實我也不太明白,所以就百度了一下:

UTF-8 BOM又叫UTF-8 簽名,其實UTF-8 的BOM對UFT-8沒有作用,是為了支援UTF-16,UTF-32才加上的BOM,BOM簽名的意思就是告訴編輯器當前文件采用何種編碼,方便編輯器識別,
但是BOM雖然在編輯器中不顯示,但是會產生輸出,就像多了一個空行。

我的問題就在於不應該是用BOM格式的,改一下,問題就解決了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM