Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

parse_ini_string()

Example

Parse a string in ii:

$ini = ‘
[names]
me = “Robert”
you = “Peter”

[urls]
first = “http://www.example.com”
second = “https://www.w3schools.com”
‘;

print_r(parse_ini_string($ini));

The following is the result of the code above:

Array
(
[names] => Array
  (
  [me] => Robert
  [you] => Peter
  )
[urls] => Array
  (
  [first] => http://www.example.com
  [second] => https://www.w3schools.com
  )
)

Definition and Usage

An configuration (ini) string is parsed by the parse_ini_file() method, which then returns the settings.

Advice: This function is unrelated to the php.ini file and can be used to read in your own configuration files.

Note: The following reserved words—null, yes, no, true, false, on, off, and none—must not be used as keys for ini files. Moreover, the key cannot contain any of the reserved letters {}|&~!()^”.

Syntax

parse_ini_string(iniprocess_sectionsscanner_mode)

Parameter Values

Parameter

Description

ini

Essential. indicates which ini file to parse.

process_sections

Not required. It returns a multidimensional array containing section names and settings if set to TRUE. False is the default.

scanner_mode

Not required. may take on any of the subsequent values:
• By default, INI_SCANNER_NORMAL
• INI_SCANNER_RAW, which indicates that option values won’t be processed.

INI_SCANNER_TYPED denotes the preservation of integer, null, and boolean types whenever it is feasible. “Yes”, “on”, and “true” are changed to TRUE. “Off”, “no”, “false”, and “none” are changed to FALSE. NULL is created from “null”. If at all possible, numerical strings are transformed to integer type.

Technical Details

Return Value:

False on failure, array on success

PHP Version:

5.3+