ini 구성파일을 로드하는 parse_ini_file 함수

Posted by Albert 4784Day 1Min 20Sec ago [2012-03-15]

============================================================

 ; user.ini
; 이 파일은 샘플 구성파일입니다.
; 문자 앞에 ;를 넣으면 주석문자로 처리해 줍니다.

[first_section]
one = 1
five = 5
; BIRD php 에서 상수로 정의하겠습니다.
animal = BIRD

[second_section]
path = "/usr/local/bin"
URL = "http://www.example.com/~username"

[third_section]
phpversion[] = "5.0"
phpversion[] = "5.1"
phpversion[] = "5.2"
phpversion[] = "5.3"


=============================================================

parse_ini_file 함수로 읽어 들이면, 다음과 같이 배열로 받아 오게 됩니다.

=============================================================

<?php
define
('BIRD', 'Dodo bird'
);

// ex. '1
$ini_array = parse_ini_file("user.ini"
);
print_r($ini_array
);

// ex. '2
$ini_array = parse_ini_file("user.ini", true
);
print_r($ini_array
);

/*
결과:
Array (
[one] => 1
[five] => 5
[animal] => Dodo bird
[path] => /usr/local/bin
[URL] => http://www.example.com/~username
[phpversion] => Array
(
[0] => 5.0
[1] => 5.1
[2] => 5.2
[3] => 5.3
)
)
Array (
[first_section] => Array
(
[one] => 1
[five] => 5
[animal] => Dodo bird
)
[second_section] => Array
(
[path] => /usr/local/bin
[URL] => http://www.example.com/~username
)
[third_section] => Array
(
[phpversion] => Array
(
[0] => 5.0
[1] => 5.1
[2] => 5.2
[3] => 5.3
)
)
)
*/
?>




LIST

Copyright © 2014 visionboy.me All Right Reserved.