post xml 通过 simplexml_load_string 解析问题
将如下$xml = "<?xml version='1.0' encoding='utf-8'?>
<address><street>Lot 11, Happy Street</street>
<state>Florida</state>
<country>USA</country>
</address>
"; post到服务器,服务器端通过simplexml_load_string解析,报
代码
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : String not started expecting ' or " in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Malformed declaration expecting version in C:\AppSer\.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Blank needed here in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : parsing XML declaration: '?>' expected in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Malformed declaration expecting version in C:\AppSer\.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Blank needed here in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : parsing XML declaration: '?>' expected in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in C:\AppSer\process.php on line 14
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\AppSer\process.php on line 14
错误。
通过最初的排查,我认为是因为字符被html格式化了,即通过
htmlspecialchars — Convert special characters to HTML entities方式。
所以我尝试,通过
htmlspecialchars_decode — Convert special HTML entities back to characters
方式将其格式化回来。但错误依旧。
通过google发现别的同志也遇到过这样的问题,分析出原因在于引号处理上。
通过
stripslashes — Un-quotes a quoted string
将post内容进行处理后。问题解决。
posted on 2010-03-18 18:04 flyingchen 阅读(2080) 评论(0) 编辑 收藏 举报