Location: PHPKode > scripts > ini_File > ini_file/example.php
<?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>
Return current item: ini_File