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程序设计有所帮助。

相关文章

mysq GBKl乱码

我现在有一个sql文件,里面内容是gbk的。我现在显示全是乱码。 就只是用mysql 4.0.26能显示。 用4.1以上的死活都显示不了。头大了。望大家指点指点,感恩不尽。 我...

php简单实现多字节字符串翻转的方法

本文实例讲述了php简单实现多字节字符串翻转的方法。分享给大家供大家参考。具体实现方法如下: <?php function mb_strev ($string, $en...

php实现插入排序

<?php /** * 插入排序 * @param Array $a 无序集合 * @return Array 有序集合 */ function insertS...

PHP合并两个数组的两种方式的异同

特别是+运算符,他的意思是,将右边的数组单元(去重复)追加到左边数组的后面。 复制代码 代码如下: <?php echo "\r\n第一种情况\r\n"; $a=array(1,2...

php中的登陆login

login <?php require "../include/DBClass.php"; $username=$_POST['UserName']; $password...