PHP parse_ini_file() Function
In this chapter you will learn:
- Definition for PHP parse_ini_file() Function
- Syntax for PHP parse_ini_file() Function
- Parameter for PHP parse_ini_file() Function
- Return for PHP parse_ini_file() Function
- Format of init file
- Example - Parse an ini file
Definition
The parse_ini_file() function parses an ini file and returns the settings in it in an array.
Syntax
PHP parse_ini_file() Function has the following syntax.
parse_ini_file(file,process_sections)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | ini file to check |
process_sections | Optional. | TRUE means to return is a multidimensional array with section names and settings included. Default is FALSE |
Return
The settings are returned as an associative array on success, and FALSE on failure.
Format of init file
Contents of an example "test.ini" file.
[names]// ja v a2 s.c o m
Developer = Bob
Tester = Mike
[urls]
first = "http://www.java2s.com"
second = "http://www.php.net"
Example
parse_ini_file() ignores section headers and returns each .ini key and its value as an associative array.
If you pass true as the second parameter, it makes each section header an element in the return value.
<?PHP/*j a v a2 s .com*/
$inifile = parse_ini_file("my.ini");
var_dump($inifile);
$inifile = parse_ini_file("my.ini", true);
var_dump($inifile);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP pathinfo() Function
- Syntax for PHP pathinfo() Function
- Parameter for PHP pathinfo() Function
- Return for PHP pathinfo() Function
- Example - returns an array that contains information about a path
Home » PHP Tutorial » PHP File Functions