手记

php操作xml

<?php

header ( 'content-type:text/html;charset=utf-8' );

$x = simplexml_load_file ( 'book.xml' );

$book = $x->xpath("//book[@id='103']");

echo $book[0]->name;

echo $book[0]->price;


echo '<pre>';

print_r($book);


//通过xpath查询出所有names 书籍名

$names = $x->xpath('//book/name');

echo '<pre>';

foreach($names as $k=>$v){

echo $v.'<br/>';

}

//print_r($names);

/////////////////////////////////////xml文件//////////////

<?xml version="1.0" encoding="UTF-8"?>

<books>

<book id="100">

<name>PHP技术开发</name>

<price>80</price>

</book>

<book id="101">

<name>Oracle技术</name>

<price>120</price>

</book>

<book id="102">

<name>MySQL数据库技术</name>

<price>89</price>

</book>

<book id="103">

<name>Java项目实例</name>

<price>90</price>

</book>

<book id="104">

<name>Ajax技术开发</name>

<price>50</price>

</book>

</books>


0人推荐
随时随地看视频
慕课网APP