PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Vallo Reima   PHP Request Parameter Options   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Request Parameter Options
Process request parameters assuming default values
Author: By
Last change: Update example.php
Date: 8 years ago
Size: 1,059 bytes
 

Contents

Class file image Download
<?php

/*
 * PHP parameters and Options handler
 *
 * Usage sample
 *
 * @package System
 * @author Vallo Reima
 * @copyright (C)2015
 */

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
ini_set('log_errors', false);

/* sample default options */
$def = array(
   
'sgn' => true,
   
'exf' => ['*.min.*'],
   
'sfx' => '_pkd',
   
'aon' => [],
   
'arc' => 'zip',
   
'tml' => 30
);

/* sample request */
$_GET = array('sgn' => '', 'arc' => '7z','aon' => ['add']);
$_POST = array('sfx' => '', 'arc' => 'tar', 'exf' => null);

require(
'ParmOpts.php'); // load the class

$obj = new ParmOpts(); // instantiate with default priority

$opt = $obj->Opts($def); // assign settings, update with the request values

$prm = $obj->Get(); // request parameters

/* display result */
header('Content-Type: text/html; charset=utf-8');
echo
'ParmOpts usage sample<br><br>';
echo
'Options<br>';
echo
'<pre>';
print_r($opt); // updated options
echo '</pre>';
echo
'Parameters<br>';
echo
'<pre>';
print_r($prm); // accepted parameters
echo '</pre>';