File: example/index.php

Recommend this page to a friend!
  Classes of philippe thomassigny  >  xconfig  >  example/index.php  >  Download  
File: example/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: xconfig
Parse configuration values as key value pairs
Author: By
Last change: patch 2.0.0
Date: 5 years ago
Size: 1,214 bytes
 

Contents

Class file image Download
<?php

echo '<h1>XConfig examples</h1>';

include_once
'../include/xconfig/XConfig.class.php';

$config = new \xconfig\XConfig(file_get_contents('myconfig.conf'), array('defparam1' => 'defvalue1', 'defparam2' => 'defvalue2', 'defparam3' => 'defvalue3'));

echo
'<h2>content of $config:</h2>';
print
$config;
echo
'<br />';

echo
'<h3>get a parameter to a local variable:</h3>';
$param1 = $config->parameter1;
echo
$param1 . '<br />';
echo
'<br />';

echo
'<h3>use directly a parameter into a sentence:</h3>';
foreach(
$config->parameter2 as $p)
  echo
$p . '<br />';
echo
'<br />';

echo
'<h3>set a new parameter:</h3>';
echo
'parameter3=value3<br />';
$config->parameter3 = 'value3';
echo
'<br />';

echo
'<h3>new content of $config:</h3>';
print
$config;
echo
'<br />';

echo
'<h3>iterate the $config:</h3>';
print
$config;
echo
'<br />';
 
echo
'<h2>Merge two config files:</h2>';

$globalconfig = new \xconfig\XConfig(file_get_contents('myglobalconfig.conf'));
$localconfig = new \xconfig\XConfig(file_get_contents('mylocalconfig.conf'));
$globalconfig->merge($localconfig);

echo
'<h3>Content of merged configuration:</h3>';
print
$globalconfig;
echo
'<br />';

?>

For more information send a message to info at phpclasses dot org.