Jump to: navigation, search

Php parse ini file

From w3cyberlearnings

Contents

PHP function parse_ini_file

This function parses a configuration file.

Syntax parse_ini_file

  • file: is a configuration file
  • section (optional): sets to true will returns multiple array with include the section names. Default sets to false.
  • mode (optional): can either be INI_SCANNER_NORMAL (default) or INI_SCANNER_RAW. If INI_SCANNER_RAW is supplied, then option values will not be parsed.
parse_ini_file(file, section, mode);

Example 1

File Content(SupportTool.ini)

[Zend.SupportTool]

;Zend Server files (relative to ZendServer root Dir)
zendpath=etc


; Apache Files  (relative to ZendServer Apache2 root Dir)
apachepath=logs

;Commands
cmd=netstat -a > netstat.txt

parse_ini_file

<?php

define('etc', '/etc/azend342');

// Parse without sections
$file = "SupportTool.ini";
$ini_array = parse_ini_file($file);
print_r($ini_array);

// Parse with sections
$ini_array = parse_ini_file($file, true);
print_r($ini_array);
?>

Output


Array
(
    [zendpath] => /etc/azend342
    [apachepath] => logs
    [cmd] => netstat -a > netstat.txt
)
Array
(
    [Zend.SupportTool] => Array
        (
            [zendpath] => /etc/azend342
            [apachepath] => logs
            [cmd] => netstat -a > netstat.txt
        )

)

Related Links


basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--

Navigation
Web
SQL
MISC
References