PHP code example of amattu2 / ini-parser

1. Go to this page and download the library: Download amattu2/ini-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

amattu2 / ini-parser example snippets




$config = new amattu\IniParser(__DIR__ . "/conf.ini");



$config = new amattu\IniParser(__DIR__ . "/conf.ini");

/**
 * Configuration reader constructor
 *
 * @param string $file The path to the configuration file
 * @param ?bool $sections Whether to parse individual sections or not
 * @throws TypeError
 * @author Alec M.
 */
public function __construct(string $filename, ?bool $sections = false)

$usernameOrDefault = $config->get("USERNAME", "GMAIL_SECTION", "defaultUserName");

/**
 * Get configuration file property
 *
 * @param string $key The property to get
 * @param string|null $section The section to get the property from
 * @param ?mixed $default value to return if the property is not found
 * @return $config[$key] || $default || null
 * @throws TypeError
 * @author Alec M.
 */
public function get(string $key, ?string $section = null, ?mixed $default = null) : mixed