PHP parse_ini_file() 함수
❮ PHP 파일 시스템 참조예시
"test.ini"의 내용:
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.w3schools.com"
PHP 코드:
<?php
print_r(parse_ini_file("test.ini"));
?>
위 코드의 출력은 다음과 같습니다.
Array
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => https://www.w3schools.com
)
정의 및 사용
parse_ini_file() 함수는 구성(ini) 파일을 구문 분석하고 설정을 반환합니다.
팁: 이 기능은 자신의 구성 파일을 읽는 데 사용할 수 있으며 php.ini 파일과 관련이 없습니다.
참고: null, yes, no, true, false, on, off, none과 같은 예약어를 ini 파일의 키로 사용해서는 안 됩니다. 또한 다음 예약 문자를 키에 사용해서는 안 됩니다. {}|&~!()^".
통사론
parse_ini_file(file, process_sections, scanner_mode)
매개변수 값
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:
|
기술적 세부 사항
반환 값: | 성공 시 어레이, 실패 시 FALSE |
---|---|
PHP 버전: | 4.0+ |
PHP 변경 로그: | PHP 7.0: 해시 마크(#)가 더 이상 주석으로 인식되지 않습니다. PHP 5.6.1: INI_SCANNER_TYPED 모드 가 추가되었습니다 . PHP 5.3: 선택적 scanner_mode 매개변수 가 추가되었습니다. |
더 많은 예
예시
"test.ini"의 내용:
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.w3schools.com"
PHP 코드(process_sections가 true로 설정됨):
<?php
print_r(parse_ini_file("test.ini",true));
?>
위 코드의 출력은 다음과 같습니다.
Array
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => https://www.w3schools.com
)
)
❮ PHP 파일 시스템 참조