PHP Classes

File: class_iniparser_sample.php

Recommend this page to a friend!
  Classes of Mark Quah   INIParser   class_iniparser_sample.php   Download  
File: class_iniparser_sample.php
Role: Example script
Content type: text/plain
Description: Sample Script
Class: INIParser
use ini format to generate HTML image
Author: By
Last change: Make built-in data better by using remark
Date: 22 years ago
Size: 2,897 bytes
 

Contents

Class file image Download
<?php
   
include_once "class_iniparser.php";

   
//===== EXAMPLE 1: GET INTERNAL DATA PARSING =======================
   
echo "<HR><H2>FILE MODE PARSER: INTERNAL DATA</H2><BR>";
   
$fname = __FILE__;
   
$ini = new INIPARSER($fname, 0, 1);
    if (
$ini->error_code != "OK")
        echo
$ini->error_code."<BR>";
    echo
"<B>INI STRUCTURE</B><BR>";
   
$ini->ShowItem(); // TURN ON IF YOU WANT 2 C DETAIL
   
echo "<B>GENERATE HTML TABLE</B><BR>";
   
$ini->UpdateCat('HTML', 'FIELD');
    echo
$ini->GetCatStr('HTML');
   
// end of table generation. sample data is at the end of the file
/* The data table start here
PARSERSTART
[FIELD]
TDLABEL=<TD BGCOLOR=BLUE>
TDENTRY=<TD BGCOLOR=PINK>
TD2LABEL=<TD BGCOLOR=GREY>
TD2ENTRY=<TD BGCOLOR=CYAN>
DATA=<INPUT TYPE=TEXT NAME='TEXT' VALUE='TESTING'>

[HTML,FREE]
<FORM>
<TABLE>
<TR>{TDLABEL}LABEL{TDENTRY}{DATA}
<TR>{TDLABEL}LABEL{TDENTRY}{DATA}
<TR>{TD2LABEL}LABEL{TD2ENTRY}{DATA}
<TR>{TDLABEL}LABEL{TDENTRY}{DATA}
</TABLE>
</FORM>
PARSEREND
*/

    //===== EXAMPLE 2: GET FROM EXTERNAL DATA PARSING =======================
    //==== Display Data
   
$fname = "class_iniparser_sample.dat";
   
$ext = new INIPARSER($fname, 1, 1);
    echo
"<HR><H2>FILE MODE PARSER: EXTERNAL DATA</H2><BR>";
   
//$ext->ShowItem();
   
if ($ext->error_code != "OK")
        echo
$ext->error_code."<BR>";
   
//==== NOW I GOING TO MANIPULATE DATA, 2 to 3 level deep
    // GLOBAL ==> FIELD ==> TABLE1, TABLE2 ==> FINAL ===> HTML
   
$ext->item['GLOBAL']['READONLY']= "READONLY";
   
// use this data to generate final string field
   
$field=$ext->UpdateCat('FIELD', 'GLOBAL');
   
// now generate table 1 and 2
   
$ext->UpdateCat('TABLE1', 'FIELD');
   
$table1 = $ext->GetCatStr('TABLE1');
   
$ext->UpdateCat('TABLE2', 'FIELD');
   
$table2 = $ext->GetCatStr('TABLE2');
   
// add a new category
   
$ext->item['FINAL']['TABLE1']= $table1;
   
$ext->item['FINAL']['TABLE2']= $table2;
   
$ext->item['FINAL']['DATE']= strftime("%d %m %y %H:%M");
   
// put into final HTML
   
$ext->UpdateCat('HTML','FINAL');
    echo
$ext->GetCatStr('HTML');
   
// $ext->ShowItem(); // TURN ON IF YOU WANT TO SEE DETAIL


    //==== EXAMPLE 3: GET FROM STRING INPUT
   
echo "<HR><H2>Programmed Mode PARSER</H2><BR>";
   
$str = new INIPARSER();
   
$str->ParseLine('[index]');
   
$str->ParseLine('item="ABC=AAA"');
   
$str->ParseLine('item2="DEF="');
   
$str->ParseLine('[free, FREE]');
   
$str->ParseLine('item="ABC="');
   
$str->ParseLine('item2="DEF="');
   
$str->ShowItem();
   
//==== Direct reference
   
echo "<HR><H2>DIRECT REFERENCE</H2><BR>";
    echo
"TEST: ". htmlentities($ini->item["FIELD"]['TDLABEL'])."<BR>";
    echo
"TEST: ". htmlentities($ini->item["FIELD"]['TDENTRY'])."<BR>";
    echo
"TEST: ". htmlentities($ini->item["HTML"]['2'])."<BR>";
    echo
"<BR>";
?>