php基于dom實(shí)現(xiàn)的圖書xml格式數(shù)據(jù)示例
本文實(shí)例講述了php基于dom實(shí)現(xiàn)的圖書xml格式數(shù)據(jù)。分享給大家供大家參考,具體如下:
<?php
$books = array();
$books [] = array(
'title' => 'PHP Hacks',
'author' => 'Jack Herrington',
'publisher' => "O'Reilly"
);
$books [] = array(
'title' => 'Podcasting Hacks',
'author' => 'Jack Herrington',
'publisher' => "O'Reilly"
);
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement( "books" );
$doc->appendChild( $r );
foreach( $books as $book )
{
$b = $doc->createElement( "book" );
$author = $doc->createElement( "author" );
$author->appendChild(
$doc->createTextNode( $book['author'] )
);
$b->appendChild( $author );
$title = $doc->createElement( "title" );
$title->appendChild(
$doc->createTextNode( $book['title'] )
);
$b->appendChild( $title );
$publisher = $doc->createElement( "publisher" );
$publisher->appendChild(
$doc->createTextNode( $book['publisher'] )
);
$b->appendChild( $publisher );
$r->appendChild( $b );
}
echo $doc->saveXML();
?>
運(yùn)行結(jié)果如下:
<?xml version="1.0"?> <books> <book> <author>Jack Herrington</author> <title>PHP Hacks</title> <publisher>O'Reilly</publisher> </book> <book> <author>Jack Herrington</author> <title>Podcasting Hacks</title> <publisher>O'Reilly</publisher> </book> </books>
PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
在線格式化XML/在線壓縮XML:
http://tools.jb51.net/code/xmlformat
XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress
XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP針對XML文件操作技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP錯(cuò)誤與異常處理方法總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
Linux Apache PHP Oracle 安裝配置(具體操作步驟)
本篇文章是對在Linux下安裝Apache+PHP連接Oracle的具體操作步驟進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PHP 創(chuàng)建標(biāo)簽云函數(shù)代碼
PHP創(chuàng)建標(biāo)簽云函數(shù)代碼,使用此函數(shù)創(chuàng)建標(biāo)簽云。2010-05-05
php中call_user_func函數(shù)使用注意事項(xiàng)
這篇文章主要介紹了php中call_user_func函數(shù)使用注意事項(xiàng),較為詳細(xì)的講述了call_user_func函數(shù)的用法實(shí)例與注意事項(xiàng),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-11-11
Laravel框架使用技巧之使用url()全局函數(shù)返回前一個(gè)頁面的地址方法詳解
這篇文章主要介紹了Laravel框架使用技巧之使用url()全局函數(shù)返回前一個(gè)頁面的地址,需要的朋友可以參考下2020-04-04
php FPDF類庫應(yīng)用實(shí)現(xiàn)代碼
php FPDF類庫應(yīng)用實(shí)現(xiàn)代碼2009-03-03
php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實(shí)現(xiàn)代碼
php模擬socket一次連接,多次發(fā)送數(shù)據(jù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-07-07
php utf-8轉(zhuǎn)unicode的函數(shù)
php下我們想把uft-8,轉(zhuǎn)成unicode可以用下面的函數(shù)來實(shí)現(xiàn)2008-06-06

