《PHP編程:PHP實現對xml進行簡單的增刪改查(CRUD)操作示例》要點:
本文介紹了PHP編程:PHP實現對xml進行簡單的增刪改查(CRUD)操作示例,希望對您有用。如果有疑問,可以聯系我們。
PHP應用本文實例講述了PHP實現對xml進行簡單的增刪改查(CRUD)操作.分享給大家供大家參考,具體如下:
PHP應用假如有下面xml文件:
PHP應用
<?xml version="1.0" encoding="UTF-8"?>
<setting>
<preferTime>55.8</preferTime>
<playerValue>56</playerValue>
<reduceValue>40</reduceValue>
<reduceTime>339</reduceTime>
</setting>
PHP應用如何使用php對它進行CRUD?其實像這種簡單的xml文件使用SimpleXMl
再好不過了.你可以像這樣來操作它:
PHP應用
<?php
//獲取數據 get the config data
if(isset($_GET["type"])){
if($_GET["type"]=="get"){
$xml=simplexml_load_file("../config.xml");
$config=array("preferTime"=>$xml->preferTime."",
"playerValue"=>$xml->playerValue."",
"reduceValue"=>$xml->reduceValue."",
"reduceTime"=>$xml->reduceTime."");
echo json_encode($config);
}
//更新數據 update the config data
if($_GET["type"]=="update"){
$xml=simplexml_load_file("../config.xml");
$xml->preferTime=$_GET["data"]["preferTime"];
$xml->playerValue=$_GET["data"]["playerValue"];
$xml->reduceValue=$_GET["data"]["reduceValue"];
$xml->reduceTime=$_GET["data"]["reduceTime"];
$xml->asXML("../config.xml");
echo json_encode("save success!");
}
}
PHP應用更多詳情可參考PHP官方usage examples? 和 API description .
PHP應用PS:這里再為大家提供幾款關于xml操作的在線工具供大家參考使用:
PHP應用在線XML/JSON互相轉換工具:
http://tools.jb51.net/code/xmljson
PHP應用在線格式化XML/在線壓縮XML:
http://tools.jb51.net/code/xmlformat
PHP應用XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress
PHP應用XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat
PHP應用更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP針對XML文件操作技巧總結》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《PHP錯誤與異常處理方法總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
PHP應用希望本文所述對大家PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/783.html