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 Marko Schulz  >  Parse INI  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: Parse INI
Parse INI files and get values into arrays
Author: By
Last change:
Date: 2012-09-10 07:55
Size: 1,638 bytes
 

Contents

Class file image Download
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example file of the class ParseINI</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>

<body>

<?php

// Path to the example ini file
(string) $file "example.ini";

// Include the class file
include_once('parseini.class.php');

try {
    
// You can also define the class properties in the class constuctor
    // (object) $ini = new ParseINI(array('file' => $file, 'quote' => '"'));

    // Create new ini object
    
(object) $ini = new ParseINI();

    
// Set the class properties like file and quote
    
$ini->setVar('file'$file);
    
$ini->setVar('quote''"');

    
// parse the defined inifile
    
(array) $data $ini->parse();

    
// Output
    
echo "<hr/>\n";
    if (isset(
$data['general']['host']) && isset($data['general']['ipaddr']))
        echo 
"All Services for ".$data['general']['host']." (".$data['general']['ipaddr'].")<br/>\n";
    if (isset(
$data['general']['description']))
        echo 
"Description: ".$data['general']['description']."<br/>\n";
    echo 
"<hr/>\n\n";

    if (isset(
$data['services'])) {
        echo 
"<h3>There are ".count($data['services'])." services defined</h3>\n\n";
        echo 
"<table border=\"1\">\n";
        echo 
"\t<tr>\n";
        echo 
"\t\t<th>Service</th>\n";
        echo 
"\t\t<th>Port</th>\n";
        echo 
"\t</tr>\n";
        foreach (
$data['services'] as $service) {
            echo 
"\t<tr>\n";
            echo 
"\t\t<td>".$service['name']."</td>\n";
            echo 
"\t\t<td>".$service['port']."</td>\n";
            echo 
"\t<tr>\n";
        }
        echo 
"</table>\n";
    }

} catch ( 
Exception $error ) {
    echo 
"Error: ".$error->getMessage()." on Line: ".$error->getLine()." in ".$error->getFile()."<br/>\n";
}

?>

</body>
</html>