在php文件中xml格式
本人是小白,有错误的地方请指正,勿喷!
在写一个调查问卷的过程中用到了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浏览器上的错误:
This page contains the following errors:
Below is a rendering of the page up to the first error.
需要改正的地方是:
去掉第一句: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.
<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>
";
最新文章
- java多线程同步,等待,唤醒
- poj3740
- 实验七 状态机设计ADC0809采样控制电路
- ZOJ-3946 Highway Project (最短路)
- eclipse 恢复被删除的文件
- mybatis和hibernate区别和应用场景
- Java SE学习之printf 日期转换符
- 检查DISPLAY设置时Xlib出现No protocol specified错误
- bzoj:3616: War
- Spring Boot系列(一) Spring Boot准备知识
- Unity UGUI实现鼠标拖动图片
- 权限管理系统之项目框架搭建并集成日志、mybatis和分页
- MySQL建表 TIMESTAMP 类型字段问题
- CentOS7安装Jenkins自动化部署maven项目
- html 网页生产pdf文件
- MFC文档应用程序CToolBar:设置两个工具条并列停靠到同一条边上 转
- Solidity safesub防止溢出
- Scala具体解释---------控制结构和函数
- js打印相关,注意此方法受到IE安全性设置影响
- 台州学院maximum cow训练记录
热门文章
- [Linux] 检查是否已有进程在运行
- [Inno Setup] Do not show application version in “Program and Features” control panel
- hdu_2391 Filthy Rich DP
- vue2.x学习笔记(二十五)
- 解决Vue-cli3.0下scss文件编译过慢、卡顿问题
- MySQL重新初始化安装数据库
- Blockchain
- 基于TCP的客户端和服务器端的代码设计
- bzoj4173 数学
- linux 服务器/客户端 tcp通信的简单例子