為什么xml格式加了header("Content-Type:text/xml");就報錯?
出現這樣的錯誤:
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.
header()不管放哪都出錯,前面也沒有輸出,卡在這里好久了,求助
2016-04-19
因為“text/html; charset=utf-8” 這一串信息所描述的就是一個屬性:內容的格式(即Content-Type)。
XML的設計,并不是為了數據存儲與查詢,而是為了規范、合理、統一地描述數據。所以XML的屬性設計與數據庫表的字段設計并不一樣。從數據庫表設計的角度,把text/html; charset=utf-8拆成兩個甚至三個字段都是合理的。但是對于XML而言并不是這樣。這三個屬性的作用很明確而且無歧義:保證數據接受者能正確解析其內容。單獨拿出來任何一個屬性都做不到這一點。那么對于XML而言,它們就應該被放在一起。
2016-04-19
header()方法寫在文件第一行
<?php
header('Content-type: text/xml');
不要講header()方法寫在后面
參考這個鏈接 ?http://stackoverflow.com/questions/21261627/error-on-line-1-at-column-6-xml-declaration-allowed-only-at-the-start-of-the-do