php使用simplexml_load_file加载XML文件并显示XML的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php使用simplexml_load_file加载XML文件并显示XML的方法。分享给大家供大家参考。具体实现方法如下:

<?php
  $xml = simplexml_load_file("sample.xml");
  echo htmlspecialchars($xml->asXML());
?>

sample.xml文件内容如下

<library>
  <book>
   <title>A</title>
   <author gender="female">B</author>
   <description>C</description>
  </book>
  <book>
   <title>C</title>
   <author gender="male">D</author>
   <description>E</description>
  </book>
  <book>
   <title>F</title>
   <author gender="male">G</author>
   <description>H</description>
  </book>
</library>

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP函数microtime()用法与说明

定义和用法PHP函数microtime()返回当前 Unix 时间戳和微秒数。PHP函数microtime()语法microtime(get_as_float)PHP函数microtim...

PHP计数器的实现代码

复制代码 代码如下:<?php/*使用文本文件记录数据的简单实现*/$counter=1;if(file_exists("mycounter.txt")){$fp=fopen("m...

PHP实现网站应用微信登录功能详解

PHP实现网站应用微信登录功能详解

本文实例讲述了PHP实现网站应用微信登录功能。分享给大家供大家参考,具体如下: 背景 近期进行 PC 端的网站开发,需要用到微信授权登录,考虑到前期手机端已经获得了大量的微信用户...

php生成无限栏目树

栏目数组: $arr=Array( Array('cid' => 2,'cname' => '新闻','pid' => 0), Array('cid' =&...

hessian 在PHP中的使用介绍

hessian 在PHP中的使用介绍

一、hessian是什么? 看到这个单词我还不知道怎么读,音标是[hes]读黑森。 Hessian是一个轻量级的远程的数据交换工具,使用简单的方法提供了RMI(远程方法调用)的功能. 相...