為什么xml格式加了header("Content-Type:text/xml");就報錯?
出現(xiàn)這樣的錯誤:
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” 這一串信息所描述的就是一個屬性:內(nèi)容的格式(即Content-Type)。
XML的設(shè)計,并不是為了數(shù)據(jù)存儲與查詢,而是為了規(guī)范、合理、統(tǒng)一地描述數(shù)據(jù)。所以XML的屬性設(shè)計與數(shù)據(jù)庫表的字段設(shè)計并不一樣。從數(shù)據(jù)庫表設(shè)計的角度,把text/html; charset=utf-8拆成兩個甚至三個字段都是合理的。但是對于XML而言并不是這樣。這三個屬性的作用很明確而且無歧義:保證數(shù)據(jù)接受者能正確解析其內(nèi)容。單獨拿出來任何一個屬性都做不到這一點。那么對于XML而言,它們就應(yīng)該被放在一起。
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