PHP Classes

File: Examples/Main.php

Recommend this page to a friend!
  Classes of Nicola Covolo   XML Manager   Examples/Main.php   Download  
File: Examples/Main.php
Role: Example script
Content type: text/plain
Description: some examples
Class: XML Manager
Store and retrieve configuration options in XML
Author: By
Last change: moved
Date: 12 years ago
Size: 1,456 bytes
 

Contents

Class file image Download
<?php
include('../class.xml.php');

//---Reading one config item---
$c = xml::getInstance('configs/config.xml');
echo
$c->get_config('version');

//---Reading all config items---
$c = xml::getInstance('configs/config.xml');
print_r($c->get_configs());

//---Updating(only) one config item---
$c = xml::getInstance('configs/config.xml');
$c->write_config('version', 'blabla', false);

//---Upating config items---
$c = xml::getInstance('configs/config.xml');
$newConfigs = array(
   
'version' => '2.10.2',
   
'game_speed' => 3000,
   
'fleet_speed' => 3000);
$c->write_config($newConfigs);

//---Adding one new config item---
$c = xml::getInstance('configs/config.xml');
$c->write_config('key', 'value');

//---Adding new config items---
$c = xml::getInstance('configs/config.xml');
$newConfigs = array(
   
'myConf1' => 'wine',
   
'myConf2' => 'pizza',
   
'myConf3' => 'spaghetti');
$c->write_config($newConfigs);

//---Working with multiple configuration files---
$c = xml::getInstance('configs/config.xml');
$d = xml::getInstance('configs/config2.xml');
$e = xml::getInstance('configs/config3.xml');
$c->write_config('version', '2.10.1');
$d->write_config('version', '2.10.2');
$e->write_config('version', '2.10.3');
echo
$c->get_config('version');
echo
$d->get_config('version');
echo
$e->get_config('version');

//--- Fix concurrency issue---
$c = xml::getInstance('configs/config.xml', true);

?>