<?php
require_once('class.config_base.php');
require_once('class.config_writer.php');
// set config file to write to
$writer = new config_writer('writable_config.txt');
// turn debuggin on
$writer->set('debug', true);
// prefix variable names with type?
$writer->set('prefix_with_type', true);
// variables to store
$var1 = "Hello";
$var2 = 100;
$var3 = "new line: \n carriage return: \r tab: \t";
$array = array(10, 20, 30);
$assoc = array('hello'=>10, 20, 'bye'=>30, 'string');
$double = 200.23;
$boolval = array(true, false);
// set parameters
// var val comment section
$writer->set_param('var1', $var1, 'Basic String');
$writer->set_param('var2', $var2, 'Basic Integer');
$writer->set_param('var3', $var3, 'Special characters');
$writer->set_param('array', $array, 'Array', 'Array Section');
$writer->set_param('assoc', $assoc, 'Assoc Array', 'Array Section');
$writer->set_param('double', $double, 'Double');
$writer->set_param('boolval', $boolval, 'Boolean', 'Boolean');
// write!
$result = $writer->write();
echo "<pre>\n";
if ($result) {
echo "Written Successfully!\n";
echo "Config is: ".($writer->is_valid($writer->build()) ? "VALID" : "INVALID")."\n";
echo "<a href=\"writable_config.txt\">View Config</a>";
} else {
echo "Could not write config file";
}
echo "\n</pre>";
?> |