Login   Register  
PHP Classes
elePHPant
Icontem

File: example

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Daniel Jšnecke  >  PHP INI Class  >  example  >  Download  
File: example
Role: Documentation
Content type: text/plain
Description: small examples
Class: PHP INI Class
Handle ini files and defaults
Author: By
Last change:
Date: 11 years ago
Size: 1,346 bytes
 

Contents

Class file image Download
Example for ini.class.php

I assume that those example files exist and that the class definition is already
available...

File: settings.ini
	[global]
	foo = bar
	version = PHP_VERSION
-----[ EOF ]-----

File: defaults,ini
	[global]
	a_default = a_value
-----[ EOF ]-----



An example of retrieving the settings of an ini-file as associative array, 
parsing constants is on:
	<?
	
		$my_ini = new ini;
		$my_ini->parse_constants = FALSE;
		$array = $my_ini->read_ini ( 'settings.ini', TRUE );
		print_r ( $array );
		
	?>

would result in:
	Array
	(
	    [global] => Array
	        (
	            [foo] => bar
	            [version] => PHP_VERSION
	        )
	
	)

Note: 
	the same example with setting parse_constants to TRUE (deafult) would result
	in PHP_VERSION being replaced by the actual version (e.g. 4.2.2)

--------------------------------------------------------------------------------

An example of working with an ini-file and an defaults-file
	<?
	
		$my_ini = new ini ( 'settings.ini', 'defaults.ini' );
		
		$foo = $my_ini->get ( 'foo', 'global' );
		print_r ( $foo );
		
		$foo = $my_ini->get ( 'a_default', 'global' );
		print_r ( $foo );
		
		$foo = $my_inin->get ( 'not_available' );
		print_r ( $foo );
		
	?>

would result in:

	bar
	a_value
	[NULL]