Php parse_ini_file example

Complete PHP Filesystem Reference

Definition and Usage

The parse_ini_file[] function parses a configuration [ini] file and returns the settings in it in an array.

Syntax

parse_ini_file[file,process_sections]


ParameterDescription
file Required. Specifies the ini file to check
process_sections Optional. If set to TRUE, it returns is a multidimensional array with section names and settings included. Default is FALSE

Tips and Notes

Tip: This function can be used to read in your own application's configuration files, and has nothing to do with the php.ini file.

Note: The following reserved words must not be used as keys for ini files: null, yes, no, true, and false. Furthermore, there are also some reserved characters that must not be used in the keys: {}|&~![[]".

Example 1

Contents of "test.ini":

[names]
me = Robert
you = Peter

[urls]
first = "//www.example.com"
second = "//www.w3schools.com"

PHP code:

The output of the code above will be:

Array
[
[me] => Robert
[you] => Peter
[first] => //www.example.com
[second] => //www.w3schools.com
]

Example 2

Contents of "test.ini":

[names]
me = Robert
you = Peter

[urls]
first = "//www.example.com"
second = "//www.w3schools.com"

PHP code [with process_sections set to true]:

The output of the code above will be:

Array
[
[names] => Array
  [
  [me] => Robert
  [you] => Peter
  ]
[urls] => Array
  [
  [first] => //www.example.com
  [second] => //www.w3schools.com
  ]
]

Complete PHP Filesystem Reference

PHP function parse_ini_file[] and example

In this part of the tutorial we will learn about the function parse_ini_file[] in context of file handling. And also we will see the example related to the parse_ini_file[] function

In this part of the tutorial we will learn about the function parse_ini_file[] in context of file handling. And also we will see the example related to the parse_ini_file[] function

Syntax of PHP parse_ini_file[] Function

  • It is used to parse ini file.ini.
  • file.ini is configuration file
  • After parsing it returns the settings of the ini file in array form


PHP parse_ini_file[] Function with Example

Code For PHP parse_ini_file[] Function

make a sample.ini with the content

name = roseindia
domain= net
[second_section]
path = "/usr/local/bin"
URL = "//www.roseindia.net"
[third_section]
phpversion[] = "5.0"
phpversion[] = "5.1"
phpversion[] = "5.2"
phpversion[] = "5.3"

Output
name->roseindia
domain->net
path->/usr/local/bin
URL->//www.roseindia.net
phpversion->Array

Complete PHP Filesystem Reference

Definition and Usage

The parse_ini_file[] function parses a configuration [ini] file and returns the settings in it in an array.

Syntax

parse_ini_file[file,process_sections]


ParameterDescription
file Required. Specifies the ini file to check
process_sections Optional. If set to TRUE, it returns is a multidimensional array with section names and settings included. Default is FALSE

Tips and Notes

Tip: This function can be used to read in your own application's configuration files, and has nothing to do with the php.ini file.

Note: The following reserved words must not be used as keys for ini files: null, yes, no, true, and false. Furthermore, there are also some reserved characters that must not be used in the keys: {}|&~![[]".

Example 1

Contents of "test.ini":

[names]
me = Robert
you = Peter

[urls]
first = "//www.example.com"
second = "//www.w3schools.com"

PHP code:

The output of the code above will be:

Array
[
[me] => Robert
[you] => Peter
[first] => //www.example.com
[second] => //www.w3schools.com
]

Example 2

Contents of "test.ini":

[names]
me = Robert
you = Peter

[urls]
first = "//www.example.com"
second = "//www.w3schools.com"

PHP code [with process_sections set to true]:

The output of the code above will be:

Array
[
[names] => Array
  [
  [me] => Robert
  [you] => Peter
  ]
[urls] => Array
  [
  [first] => //www.example.com
  [second] => //www.w3schools.com
  ]
]

Complete PHP Filesystem Reference

What is Parse_ini_file?

The parse_ini_file[] function parses a configuration [ini] file and returns the settings. Tip: This function can be used to read in your own configuration files, and has nothing to do with the php. ini file.

How do I create a PHP ini file?

How to Manually Create a PHP..
Log into your cPanel account..
Open your File Manager..
Navigate to your public_html directory..
Create a new file..
Name it php.ini..
Edit the php.ini file you just created..
Copy and Paste the default php. ini code from the copy of the default version below..
Click Save Changes..

How do I read a .ini file?

How to Open and Edit INI Files. It's not a common practice for people to open or edit INI files, but they can be opened and changed with any text editor. Just double-clicking it will automatically open it in the Notepad application in Windows.

What is ini file in PHP?

The php. ini file is the default configuration file for running applications that require PHP. It is used to control variables such as upload sizes, file timeouts, and resource limits. php. ini file is the configuration file.

Bài mới nhất

Chủ Đề