惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
G
Google Developers Blog
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
J
Java Code Geeks
U
Unit 42
云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
N
Netflix TechBlog - Medium
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
Docker
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
V
V2EX
T
Tailwind CSS Blog

博客园 - flyingchen

gcc的一个困惑 敏捷项目组 javascript string to date - flyingchen 熟悉了以下VIM指令,你会爱死她的 ajax应用如何做好seo - flyingchen - 博客园 nestful - ruby http-rest 客户端 分析 Liskov替换原则与继承 Linux Commands Cannot find autoconf. Please check your autoconf installation pecl报错(1) - flyingchen - 博客园 关于角色访问控制(RBAC) awk学习 php实现单件模式总结(持续更新) 激动网 PHP高级开发工程师 招聘 rsync的命令格式 rsync从linux到linux的文件同步备份 zend + apache + config stop words mmseg 安装错误 error: ’strncmp’ was not declared in this scope
post xml 通过 simplexml_load_string 解析问题 - flyingchen
flyingchen · 2010-03-18 · via 博客园 - flyingchen

将如下$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

错误。

通过最初的排查,我认为是因为字符被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内容进行处理后。问题解决。