php解析xml字符串
2024-08-31 18:33:14
<?php
$content = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<test>
<global_setting>
<ping_protocol>HTTP</ping_protocol>
<ping_port>80</ping_port>
<ping_path>/index.html</ping_path>
<response_timeout>5000</response_timeout>
<health_check_interval>3000</health_check_interval>
<unhealthy_threshold>2</unhealthy_threshold>
<healthy_threshold>3</healthy_threshold>
</global_setting>
<instances>
<instance ip="192.168.234.121"/>
<instance ip="192.168.234.28"/>
</instances>
</test>
XML; $test = new SimpleXMLElement($content); //获得ping_protocol的值
$ping_protocol = $test->global_setting->ping_protocol;
echo "ping_protocol : $ping_protocol \n"; //打印出所有instance的IP
foreach ( $test->instances->instance as $instance) {
echo "IP: {$instance['ip']} \n" ;
} //经过我的测试,发现试用var_dump之类的似乎不能有效输出值,用echo比较顺利,还有就是上面的那个xml的例子可以去掉<?xml version="1.0" encoding="UTF-8"?> 也可以去掉头尾///的<<<xml,然后当做普通字符串那样对待,但是没有测试中文等
最新文章
- [转]看部电影,透透彻彻理解IoC(你没有理由再迷惑!)
- 配置文件类 Properties
- Qt——设计颜色编辑器
- Rainyday.js – 使用 JavaScript 实现雨滴效果
- 《DSP using MATLAB》示例Example4.7
- FindProcDLL::FindProc 和 KillProcDLL::KillProc,必须使用WPF x86编译出来的程序
- 【WinRT】国内外 Windows 应用商店应用开发者博客收集
- 20135316王剑桥 linux第二周课实验笔记
- pap与chap协议
- android的个人代码总结
- MapXtrem + Asp.net 地图随窗体改变大小
- XJOI1424解压字符串
- 【技巧】datagrid锁定列后重新加载时出现错位问题的解决
- Android实现购物车功能
- UITableView 之 点击cell 实现两个自定义cell之间的切换
- SSO 基于CAS实现单点登录 实例解析(二)
- 【spring实战第五版遇到的坑】3.1中的例子报错
- C#二维码与条形码的生成
- 1.5 A better alternative thing: React Native
- ERP服务启动后无法连接数据库的解决方法
热门文章
- system.setting-全局变量数据监听
- https://github.com/ 英文库
- 记号(notation)的学习
- 体验SUSE (附视频演示)
- 通过NFS、FTP、HTTP三种方法安装Redhat Linux (高清版)
- Navigator对象关于语言的属性
- BZOJ1023: [SHOI2008]cactus仙人掌图(仙人掌)
- [Vue + TS] Use Properties in Vue Components Using @Prop Decorator with TypeScript
- IIS7性能优化
- 8.spring-boot配置log4j