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去除数组中重复的元素并按键名排序函数

1、此函数的作用:去除数组中重复的元素并按键名排序 function assoc_unique($arr, $key) { $tmp_arr = array(); foreach($ar...

Swoole实现异步投递task任务案例详解

Swoole实现异步投递task任务案例详解

本文实例讲述了Swoole实现异步投递task任务案例。分享给大家供大家参考,具体如下: 【使用场景】       Swolle的t...

PHP OPCode缓存 APC详细介绍

PHP OPCode缓存 APC详细介绍

APC的介绍 The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is t...

PHP及Zend Engine的线程安全模型分析

PHP及Zend Engine的线程安全模型分析

不知道怎么回事总是令人不舒服的,因此我通过阅读源码和查阅有限的资料简要了解一下相关机制,本文是我对研究内容的总结。 本文首先解释了线程安全的概念及PHP中线程安全的背景,然后详细研究了P...

PHP实现简单聊天室(附源码)第1/2页

一,聊天室模块实现1,聊天室主页面窗口设置复制代码 代码如下:<meta http-equiv="Content-Type" content="text/html; charset...