PHP parse_ini_file() Functie
❮ Referentie voor PHP-bestandssysteemVoorbeeld
Inhoud van "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.w3schools.com"
PHP-code:
<?php
print_r(parse_ini_file("test.ini"));
?>
De uitvoer van de bovenstaande code zal zijn:
Array
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => https://www.w3schools.com
)
Definitie en gebruik
De functie parse_ini_file() parseert een configuratiebestand (ini) en retourneert de instellingen.
Tip: Deze functie kan worden gebruikt om uw eigen configuratiebestanden in te lezen en heeft niets te maken met het php.ini-bestand.
Opmerking: De volgende gereserveerde woorden mogen niet worden gebruikt als sleutels voor ini-bestanden: null, yes, no, true, false, on, off, none. Verder mogen de volgende gereserveerde tekens niet in de sleutel worden gebruikt: {}|&~!()^".
Syntaxis
parse_ini_file(file, process_sections, scanner_mode)
Parameterwaarden
Parameter | Description |
---|---|
file | Required. Specifies the ini file to parse |
process_sections | Optional. If set to TRUE, it returns is a multidimensional array with section names and settings included. Default is FALSE |
scanner_mode |
Optional. Can be one of the following values:
|
Technische details
Winstwaarde: | Een array op succes, FALSE op mislukking |
---|---|
PHP-versie: | 4.0+ |
PHP-wijzigingslogboek: | PHP 7.0: Hekjes (#) worden niet langer herkend als opmerkingen PHP 5.6.1: INI_SCANNER_TYPED-modus toegevoegd PHP 5.3: optionele scanner_mode- parameter toegevoegd |
Meer voorbeelden
Voorbeeld
Inhoud van "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.w3schools.com"
PHP-code (met process_sections ingesteld op true):
<?php
print_r(parse_ini_file("test.ini",true));
?>
De uitvoer van de bovenstaande code zal zijn:
Array
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => https://www.w3schools.com
)
)
❮ Referentie voor PHP-bestandssysteem