simplexml_load_string報錯:XML declaration allowed only at the start of the document

xml數據,data裏的爲xml數據。註明:帶有\r\n的。

{"status_code":200,"msg":true,"data":"\r\n\r\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><error>0<\/error><message><\/message><\/response>\r\n\r\n"}


在進行轉換爲字符串simplexml_load_string的時候會報錯:XML declaration allowed only at the start of the document


解決辦法:

rtrim($data) 加  ltrim($data)。曾經試過直接trim,但是不知爲何不管用。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章