在写一个调查问卷的过程中用到了xml文件,如想要了解,可以通过以下链接简单学习:http://www.w3school.com.cn/xml/
所用工具:phpstudy+notepad++(使用utf-8编码无bom)
出现的问题如下:最开始的代码如下:我想要 求出去长沙游玩的人数是多少人,
<?php
header('content-type: text/xml');
$xmlstr="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
$xml = simplexml_load_string($xmlstr);
$count0 = $xml->movie[0]->count;
echo $count0;
?>
火狐浏览器上:
xml 解析错误:语法错误
位置:http://localhost:8080/diaocha/2.php
行 1,列 1:350
360浏览器上的错误:
需要改正的地方是:
去掉第一句:header('content-type: text/xml');即可。得到350
2、如果你是需要查看xml格式的时候
代码如下:
<?php
header('content-type: text/xml');
$xmlstr="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
就可以得出结果:
this xml file does not appear to have any style information associated with it. the document tree is shown below.
如对本文有疑问, 点击进行留言回复!!
如何去设计前端框架能力?星巴克消息开放项目从0到1,从点到面的思考
PHP制作日历,实现在1970年到2020年之间的任何一个月份的输出。上半部分
网友评论