Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of James Barwick  >  ini_File  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: This is an example of a simple web page using the ini_File.php INI file object model.
Class: ini_File
Manipulate INI configuration files as PHP objects
Author: By
Last change:
Date: 2007-11-16 02:57
Size: 2,104 bytes
 

Contents

Class file image Download
<?php
session_name
('PHPSESSID');
$result session_start();
if (!
$result) { echo "Cannot start session"; exit; }

require_once(
'ini_File.php');

?>
<html>
<head><title>Test INI Loader</title>
<style>
th {
   font: 10pt Arial;
   font-weight: bold;
}
td {
   font: 8pt Arial;
}
</style>
</head>
<body>
<?php

if (IsSet($_SESSION['inifile2'])) {
    
$inifile unserialize($_SESSION['inifile2']);
    echo 
"Using Session<br /><br />\n\n";
}
else {
    
$filename "/tmp/test.ini";
    
$inifile = new ini_File($filename);
    
$inifile->read();
    
$_SESSION['inifile2']=serialize($inifile);
    echo 
"reading file<br /><br />\n\n";
}

$sections $inifile->getSections();

?>
Sections: <select name="section" size="1">
<?php
    
foreach ($sections as $key => $section) {
        echo 
"<option value=".$key.">";
        echo 
$section->getName();
        echo 
"</option>\n";
    }
?>
</select>
<br><br>
<?php
    
foreach ($sections as $key => $section) {
        echo 
"Section: [".$section->getName()."]<br>\n";
        echo 
"<div style=\"padding:5px;border: 1px solid gray;background-color:#CFCFFF;\" id=\"".$key."\">";
        
//echo "<pre>".$section->toString()."</pre>\n";

        
$values $section->getValues();
        if (
sizeof($values)>0) {
        echo 
"<table width=\"900\" cellpadding=\"2\" cellspacing=\"0\" border=\"1\">\n";
        echo 
"<thead>\n";
        echo 
"<tr><th width=\"200\">Key</th><th width=\"300\">Value</th><th width=\"400\">Comment</th></tr>\n";
        echo 
"</thead>\n<tbody>";
        foreach (
$values as $value_key => $value_object) {
            
$commentObject $value_object->getComment();
            if (!empty(
$commentObject))
                
$comment $commentObject->toString();
            else
                
$comment="&nbsp;";
            echo 
"<tr><td>".$value_object->getName()."</td><td>".$value_object->getContent()."</td><td>".$comment."</td></tr>\n";
        }
        echo 
"</tbody>\n";
        echo 
"</table>\n";
        }
        echo 
"</div><br>\n";
    }
?>
</body>
</html>